Hi Team, is it possible in GD to get a distinct co...
# gooddata-cloud
c
Hi Team, is it possible in GD to get a distinct count of player_id for each recency group, where the recency groups are defined using a CASE WHEN?
k
This is a known limitation in GoodData MAQL. Here's what you need to know: The Core Constraint Your metric (shown in the screenshot) uses
CASE WHEN
on
{fact/recency_days}
to define recency buckets. While
COUNT
in MAQL already returns distinct values by default (no separate
DISTINCT
keyword is needed), combining
CASE WHEN
with a distinct count per group in a single metric is not directly supported —
CASE
does not work at the base data level and evaluates on the aggregation dimension, meaning you cannot do
COUNT(DISTINCT player_id) WHERE CASE WHEN ...
in a single MAQL metric. [CASE statement] Recommended Approaches 1. Precompute the recency group (most robust) Add a
recency_group
column (e.g.,
"<30"
,
"31-90"
,
"91-365"
,
"Year+"
) at the ETL/SQL level or via a SQL Dataset in GoodData. Then simply use:
Copy code
SELECT COUNT({label/player_id})
...sliced by the
recency_group
attribute in a table visualization. GoodData will automatically return the distinct count of
player_id
per group. [CASE statement] 2. Separate metrics per bucket (MAQL-only workaround) If you need to keep the logic purely in MAQL, create separate metrics for each recency bucket using a
WHERE
condition, and display them side by side in a visualization. This avoids the dynamic grouping limitation but requires one metric per bucket. The precomputed attribute approach is the recommended pattern for bucketing use cases in GoodData Cloud, as it sidesteps the MAQL
CASE
limitation entirely and keeps your metrics maintainable. [CASE statement] 👍 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.
j
Hi Cathy, we can certainly look directly into the workspace for building this type of metric. Would you please be able to send the json file of the LDM over? Or, if you provide a link to the workspace you are working on we can access it as the admin from Support. Understanding the LDM will help with the construction of the metric.
c
Thanks Joseph, I’ve created it in the LDM and it’s working, but I’ve run into another issue, the SQL query is greyed out and I can’t edit it anymore. The link is: Model Data - GoodData Cloud
j
Hi Cathy, Thanks for the link. I've just accessed the LDM and I am able to edit the sql by clicking on the pencil to the right
Could you please let us know if this is not working?