Krishti Bikal
03/14/2026, 1:41 PMkapa.ai
03/14/2026, 1:41 PMWHERE clauses and combine metrics to isolate each customer segment.
-------------------------
Building the KPIs
Step 1: Define Base Count Metrics
First, create two helper metrics that count distinct customers per order type:
Customers with Re-order:
SELECT COUNT({attribute/customer_number}) WHERE {label/order_type} = "reorder"
Customers with Pre-order:
SELECT COUNT({attribute/customer_number}) WHERE {label/order_type} = "preorder"
-------------------------
Step 2: Define the Three KPI Metrics
Re-order Only (has reorder, no preorder):
SELECT COUNT({attribute/customer_number})
WHERE {label/order_type} = "reorder"
AND {label/customer_number} NOT IN (
SELECT {label/customer_number} WHERE {label/order_type} = "preorder"
)
> Note: MAQL supports WHERE with `IN`/`NOT IN` for attribute values [Relational Operators], but nested subqueries filtering on customer membership are complex. A more practical approach in GoodData is described below.
-------------------------
Recommended Practical Approach in GoodData
Since MAQL metrics are context-aware and multidimensional [MAQL Multidimensionality], the cleanest way to build these KPIs is:
1. Create two base metrics (count of customers per order type as above).
2. Use them in a Pivot Table sliced by Customer Number to see, per customer, whether they have reorders, preorders, or both.
3. For summary KPIs, define metrics using BY and ALL OTHER to lock aggregation grain [BY keyword].
For the "Both" KPI (customers with both order types), you can leverage the fact that a customer appears in both base metrics:
-- Customers with BOTH: count customers where reorder count > 0 AND preorder count > 0
SELECT COUNT({attribute/customer_number})
WHERE {label/order_type} = "reorder"
AND {label/order_type} = "preorder"
> â ī¸ The knowledge sources do not explicitly cover multi-value set membership checks (e.g., "customer has both values of an attribute") in a single MAQL expression. For complex segmentation like this, GoodData's AI Assistant Metric Skill can help generate the appropriate MAQL [Metric Skill], or you may need to pre-compute customer segments in your data source (e.g., add a customer_segment column with values reorder_only, preorder_only, both) and then use simple WHERE filters:
-- Re-order Only
SELECT COUNT({attribute/customer_number}) WHERE {label/customer_segment} = "reorder_only"
-- Pre-order Only
SELECT COUNT({attribute/customer_number}) WHERE {label/customer_segment} = "preorder_only"
-- Both
SELECT COUNT({attribute/customer_number}) WHERE {label/customer_segment} = "both"
This pre-computation approach is the most reliable and performant path for this type of customer segmentation in GoodData. đ 0 button đ 0 button âšī¸ Tip: Mention @kapa.ai in the thread for follow-ups.
đ Our Support team monitors all messages and will jump in if needed.Krishti Bikal
03/14/2026, 2:02 PMSELECT COUNT({attribute/customer_number})
WHERE {label/order_type} = "reorder"
AND {label/customer_number} NOT IN (
SELECT {label/customer_number} WHERE {label/order_type} = "preorder"
)
This is not a valid syntax - SELECT {label/customer_number} WHERE {label/order_type} = "preorder"Joseph Heun
03/16/2026, 5:16 AMJoseph Heun
03/19/2026, 8:47 AMKrishti Bikal
03/19/2026, 11:43 AMSelect ({metric/total_number_of_buyers}-(SELECT {metric/total_number_of_buyers} WHERE {label/orders_summary.order_type}="Pre-order"))
Number of Buyers by Reorder only
Select ({metric/total_number_of_buyers}-(SELECT {metric/total_number_of_buyers} WHERE {label/orders_summary.order_type}="Pre-order"))
Number of Buyers by Preorder Reorder Both
Select ({metric/total_number_of_buyers}-{metric/number_of_buyers_by_preorder_only}-{metric/number_of_buyers_by_reorder_only})