Maybe someone can assist me with the MAQL here. W...
# gooddata-cloud
j
Maybe someone can assist me with the MAQL here. We are trying to calculate a "Month Ratio" for a given date filter, and we are wondering if something like this is possible? It appears we cannot reference the span of days within a given date filter / I was not able to find a way combing the docs.
Copy code
# Desired: We want to find the month Ratio that is essentially number of days in date range / 30.437 (average number of days in a month)
# We apply this ratio to a db-stored value that represents our "monthly" retainer
I am assuming the issue here is with the value i am asking for is a result of a date filter that may / may not be present, right?
i
Hi Jake, If I understand it correctly, you’d like to make the result of this metric to dynamically change, based on the selected data range in your filter. Please correct me, if I am wrong.
j
date range, yeah
i
Thanks for the confirmation, let me check internally if we can achieve this somehow.
v
Hi Jake, would this work for you? I have created something similar to your use-case in the Demo workspace This is the month ratio metric
Copy code
SELECT DATETIME_DIFF(
    MIN({label/day.day}),
    MAX({label/day.day}),
    DAY) / 30.437
  BY ALL OTHER
  USING {label/business_id}
The
BY ALL OTHER
clause makes it so the ratio will be the same for all rows. Alternative form:
Copy code
SELECT DATETIME_DIFF(
    MIN({label/day.day}, {label/business_id}),
    MAX({label/day.day}, {label/business_id}),
    DAY) / 30.437
  BY ALL OTHER
I hope this helps
🙌 1
j
hmm i will have to give this a try, thanks!