Hi GD team, i'm struggling with moql here and not ...
# gooddata-cloud
m
Hi GD team, i'm struggling with moql here and not sure whether i can use a real date as a comparison in a metric. i asked different llms to find me the exact documentation about this aspect and they keep suggesting me using DATE which doesn't seem to work in moql. Is there a way to execute my condition? Moql error log is not super helpful here unfortunately cos it's hinting that it's impossible to to compare a date (my {label/dt_m.day}) to a number (my condition '2025-10-01') but i'm not sure how to convert them. Thank you much in advance!
j
You are correct that the use of
DATE
in your MAQL condition is not valid syntax for GoodData MAQL. In MAQL, you can directly compare a date label to a date string in the correct format, without wrapping the date string in a
DATE()
function. The correct approach is to use the date label and compare it to a string that matches the format of your date attribute. For example, if your date label is
{label/dt_m.day}
and your date values are in the format
YYYY-MM-DD
, you can write:
{label/dt_m.day} >= "2025-10-01"
You do not need to use `DATE('2025-10-01')`—this is not supported in MAQL and will result in an error, as you have experienced. The comparison should be made directly between the date label and the string value, as shown in the official documentation:
SELECT {metric/profit} WHERE {label/date_ordered.date} <= "2010-12-22"
or
SELECT {metric/profit} WHERE {label/date_ordered.monthYear} < "2007-05"
(Relational Operators - GoodData Cloud) So, in your case, you should update your MAQL to:
WHEN (Brand Name {label/dim_brand.brand_name} = "..." AND Created At - Date {label/dt_m.day} >= "2025-10-01") THEN ...
Just ensure that the string
"2025-10-01"
matches the format of your
{label/dt_m.day}
attribute.
m
omg my issue was that i didn't try using ", that helped, thank you!
🙌 1
interestingly, the metric itself doesn't throw any errors after the fix, but it cannot be calculated in the analyse tab i'm getting a 'wrong case conditions' error. i tried to rewrite the metric but it keeps giving me the same error again and again. trace ids: 4fbc0b82737a3f1cf8afc80fdf3dd445 23ecadf4a16644f40e51e8e9b25485bd 2ab78b697f1af1 dea141b9f4afc5f46f any ideas what should i look into?
j
In GoodData MAQL, CASE conditions must be reachable from the metric's dimensionality. This means that all attributes or labels used in your CASE conditions must be logically connected to the attribute(s) you are grouping by (in your case,
Brand Name
). If you use attributes in your CASE conditions that are not related to the grouping attribute, the metric cannot be computed and you get this error. What To DoCheck your CASE conditions: Make sure that all attributes used in your WHEN/THEN/ELSE logic are directly related to the attribute(s) you are grouping by (here,
Brand Name
). • Use BY rule if needed: If you need to evaluate the CASE at a specific grain, use the
BY
clause to specify the correct dimensionality. • Aggregation: Always wrap your CASE in an aggregation function like
SUM
as you are already doing. Summary: Your error is due to a mismatch between the attributes used in your CASE conditions and the metric's dimensionality. Adjust your CASE logic or use the
BY
clause to resolve this, as described in the official documentation (source). In short, you will need to review your LDM and the objects used in your MAQL statment. GoodData Cloud CASE CASE is a conditional statement that performs logical tests on a series of conditions and returns values when a condition is met. The CASE function returns a numeric result. You use CASE for complex conditional expressions that contain two or more conditions. CASE is followed by WHEN/THEN keywords to specify the conditions, then by ELSE to specify the default return. If no match is found, the default return expression (ELSE) is used.
m
thank you, it seems to work now
the last question (i hope), the metric is solved but it might have broken the next level metric that is basically a sum of that one and two other metrics. it's throwing a "General error", are tehre any recommendations on how i can approach that one?
j
This actually looks like it could be another issue with the objects connected in the LDM. I would review how the LDM has been designed and make sure all the objects are connected. If you are still facing issues, could you please provide a link to the report you are working on so we can check it out?
m
hhmmm interesting, what makes you think it's ldm related? i didn't change anything there today, was just playing with the metric
j
I've checked our logs based on the traceID and there is nothing indicating exactly what the error is. Therefore, this generally falls under the LDM umbrella. MAQL metric are totally dependent on the LDM in the workspace.
m
Hi Masha, we are wondering if you have the chance to review the update of my colleague Joseph, have you checked the LDM? Let us to know if you still need our assistance.
m
sorry for not following up on that. i found a workaround for that metric and it eventually worked out so i didn't dig deeper. the problem was with a widget that was supposed to compare this year to date to the last year to date. one of the components of the core value of this widget was the metric that i was struggling with initially. so eventually i grouped that metric by day, it worked but it broke this widget. switching to the monthly non grouped value somehow helped but i'm still not sure why. so i'm not sure it was ldm related but hope this explanation helps you guys
j
Hi Masha, Thank you so much for following up with this as it will be kept in our records. Please note that when trying to troubleshoot metrics/reports sometimes it is essential for us to access the workspace to view the LDM and how those objects line up in the metric/report. Thank you for letting us know how you resolved it. Cheers!
🙏 1