Struggling with previous period MAQL versus visual...
# gd-beginners
d
Struggling with previous period MAQL versus visual. I need to use MAQL to make a bar chart with just change % but its giving me a different answer. The one on right is MAQL and its incorrect.
m
Hi Doug, I believe per the documentation the FOR PREVIOUSPERIOD takes the granularity by which to shift the data from the date granularity in the insight buckets (but not filter). Here you do not have any date on the rows/columns buckets there, so it probably uses "day" as specified in the metric by the date attribute used. Since you are filtering by week, I assume you want to shift by a week. So you might try using week in your metric instead of day.
{label/case_opened.week}
I think. Or since you are not using date, you can use the FOR PREVIOUS function (without PERIOD) and also use the week in it instead of the day.
d
Which function takes into account the pervious period of the filter of the dashboard?
I tried Previous and got the same answer. I just want it to work like it does in the UI
I want it to be dynamic
m
I am not sure if there is such function that would allow it with dynamic date filter, I am afraid. Let me try to double check it internally. I believe you could achieve the correct numbers in this scpecific case (filtered to last week) by using
FOR PREVIOUS(label/case_opened.week)
but that will not show the same as the UI if you try to filter by month, year or other date period.
While I am checking this internally, I wanted to share one option that came to my mind - I am not sure if that works for your situation, but just in case: If you want the MAQL for this dynamic calculation because you want to compare it with some other metric in the same visualization, you might do this: • use the UI method to have the previous period “metric” • have the metric you want to compare it to in the same visualization • click the “+” icon on the right side under the visualization metrics • select one of the calculation method and then select the two metrics to compare (you can also choose the previous period “metric”) This approach has several limitations: • only compare/calculate with two metrics • only choose from five calculation options (% change being among them) • you need to have both the other metrics in the visualization I verified that this works dynamically when changing the date filter.
d
I already have that set up. I'm using it to compare with the Maql. I need to get the change percentage in a bar graph and not a table which is why I need to use maql. I thought I mentioned that my original question so that isn't clear let me know The reason I can't use the UI method is you can't unselect metrics in a bar chart. It shows all of them. I just want to show the Change Percentage in a bar chart
it's odd that the UI has a function that the maql does not
m
I see and tend to agree. I’ve passed your question to the product team.
d
I think I figured it out
Nevermind. Can you have someone else join the conversation to make sure this isn't possible.
What I want to do, Is show a bar graph with the Percent changes from a period to the next based on dashboard filters so the user can figure out which is increasing the fastest
This is my current workaround, not great, but best I could do