Hi All, can you help me to understand why this MAQ...
# gd-beginners
d
Hi All, can you help me to understand why this MAQL is wrong?
Copy code
SELECT DATETIME_DIFF(THIS,Date (Customer Start),MONTH)
Unexpected 'D'. Expecting: RUNFUNCNAME, IFNULL, FUNCNAME1, ELEM_IDENTIFIER, PREVIOUS, THIS, ZERO, TEXT_ELEM, FUNCNAMEN, IF, REPORT, REAL, FUNCNAME12, OBJECT, COUNT, STRING, NEXT, FUNCNAME2, NATURAL, -, IDENTIFIER, SHORT_STRING, CASE, PERCENTILE, RANKFUNCNAME, (
1
f
Hi Dilaksha, Based on the error you got, it looks like the function wasn’t recognized. Please note that the DATETIME_DIFF function only exists in GoodData Cloud. If you are using GoodData Platform (which it seems like you are), that function cannot be used. In Platform, you would get similar results by using Date Attribute Arithmetics. Take a look there!
d
thanks, although this article does not cover if I want the result to be in months rather than days. Or am I missing somehting @Francisco Antunes
f
It can definitely be done, all you have to do is use the Month on the Date dimension in the metric, like
Month (Date)
. It will be calculated using months and will give you the result in months too 🙂
d
Okay, sorry I think my MAQL needs lots o f polishing. MONTH function takes in a date as argument Say I have two dates -
date1
and
date2
where
date2
is today, so I can use
THIS
for
date2
What I want to know is how many months between these two dates
THIS - date1
=
x
days I want this
x
to be converted into months I can't use MONTH(
x
) because
x
is not a date I can do MONTH(THIS) - MONTH(date1) but that is not what I want could you see the problem?
f
A-ha! Gotcha! In this case, you could use Conditional Number Formatting to format the days into months. kinda like so:
Copy code
[<30]Less than 1 Month;
[<60]1 month;
[<90]2 months;
[<120]3 months
In this example, the result in days will be formatted according to the conditions above, so: 1. If the value is smaller than 30, it displays “Less than 1 month”; 2. If the value is Equal or larger than 30, but smaller than 60, it displays “1 month” and so on How does that sound?
d
brilliant, that does work for me. Thanks @Francisco Antunes
🎉 2
1