Hi Guys! Do you know what's wrong here? Custom cr...
# gd-beginners
a
Hi Guys! Do you know what's wrong here? Custom created metric is not working
y
Hi Akmal, Thanks for sending this in, happy to help. The error message in your screenshot`"Missing aggregation, from='[attribute/...]' to='[]'"` indicates that your custom metric is missing an aggregation function when used with one or more attributes in the visualization. In GoodData, when you use a metric together with attributes (for example, in a bar chart grouped by categories), you must specify how the metric should be aggregated over those attributes (e.g., SUM, AVG, COUNT). This is a common requirement in GoodData MAQL and the UI: metrics must have an aggregation defined if they are to be sliced by attributes. If you do not specify an aggregation, GoodData cannot compute the metric for each attribute value, resulting in this error [Aggregation Functions]. How to fix: • Edit your custom metric and ensure you are using an aggregation function such as
SUM()
,
AVG()
,
COUNT()
, etc., around your fact or calculation. • For example, instead of
{fact/your_fact}
, use
SUM({fact/your_fact})
or another appropriate aggregation. If this doesn't help, kindly share a direct link to the report with the failing metric to allow us investigate and provide further assistance.
a
Hi @Yvonne Changamuka
Thanks for reply I'm using aggregation here, can you check please if I'm missing anything here?
SELECT IF DATETIME_DIFF({label/cleared_date.day},{label/posted_date.day} ) <=3
THEN
(SELECT IFNULL(SELECT COUNT({label/claim_id})
where {label/autopost_statuses_table.autopost_status} IN("Posted", "Pre Posted"  ) ,0))
/
(SELECT COUNT({label/claim_id}))
ELSE NULL
END
y
Hi Akmal, Your metric is failing because of how you are using aggregation and conditional logic in MAQL. Here are the key issues to note; 1. DATETIME_DIFF Usage The
DATETIME_DIFF
function is not an aggregation function. When you use it in a metric that is sliced by attributes (like claim_id), you must specify the dataset context using the
BY
keyword. For example:
SELECT DATETIME_DIFF({label/cleared_date.day}, {label/posted_date.day}) BY {dataset/your_dataset}
Without the
BY
clause, GoodData does not know how to aggregate the difference for each row, which can cause errors, more information on this in DATETIME_DIFF documentation. 2. IF/CASE and Aggregation In MAQL, conditional statements like
IF
or
CASE
should be wrapped inside an aggregation function (such as
SUM
or
AVG
) when used in a metric that is sliced by attributes. This ensures the metric is computed at the correct dimensionality CASE documentation. 3. Nesting SELECT Statements You are nesting
SELECT
statements inside your
IF
condition, which is not the recommended MAQL pattern. Instead, you should use aggregations directly and avoid unnecessary nested
SELECT
statements. 4. COUNT and IFNULL The use of
IFNULL
is correct for handling nulls, but it should be applied to the result of an aggregation, not to a nested
SELECT
. How to Fix You should rewrite your metric to: • Use
DATETIME_DIFF
with the
BY
clause. • Wrap the
IF
statement inside an aggregation (e.g.,
SUM
or
AVG
).not nested selects IF syntax
SELECT IF ( <condition> , <then_expression> , <else_expression> )
• Avoid unnecessary nested
SELECT
statements. or equivalently:
Copy code
SELECT CASE WHEN <condition> THEN <then_expression> ELSE <else_expression> END
You cannot write
SELECT IF <condition> THEN ... ELSE ... END
. Example Rewrite of how you can express what you intended (ratio of certain claims if dates are within 3 days)
SELECT
IF (
DATETIME_DIFF({label/cleared_date.day}, {label/posted_date.day}) <= 3,
(SELECT COUNT({label/claim_id})
WHERE {label/autopost_statuses_table.autopost_status} IN ("Posted", "Pre Posted"))
/
(SELECT COUNT({label/claim_id})),
NULL
)
Let me know if this helps. If not, kindly share a direct link to the report, feel free to share via dm. Thanks
a
Thank you so much @Yvonne Changamuka