Last week I wrote about how the Above() function can be used for calculating rolling averages and other accumulations. There is however also an alternative method for doing the same thing:
The As-Of table.
When you use the Above() function, you fetch a number from other rows in a chart or Aggr() table. The As-Of table is slightly different in this respect: It is not a transient table created by an object or an expression – instead it is a real table in the data model.
The idea is to create a secondary month field – the AsOfMonth - that links to multiple real months.
In the example above, you can see that ‘2015 Oct’ links to several preceding months, and each Month in turn links to several rows in a fact table. This means that a specific transaction will be linked to several AsOfMonths.
In the data model, the As-Of table should appear as a separate calendar table that links to the existing primary calendar table:
One way to create this table is the following:
First, make sure that you in your master calendar have a field “Month” that is defined as the first date of the month, e.g.
Date(MonthStart(Date),'YYYY MMM') asMonth,
Then add the following lines at the end of the script:
// ======== Create a list of distinct Months ======== tmpAsOfCalendar: LoaddistinctMonth Resident [Master Calendar] ;
I have made the Set Analysis expressions based on two fields: YearDiff and MonthDiff. However, for clarity it could be a good idea to add flags in the As-Of table, so that the Set Analysis expressions become even simpler, e.g.
I have a 12 month rolling average line chart in Qlik Sense based on this post. My data set goes back to 2001. For the rolling average chart, I only want to show the latest 3 years? Question, how can I limit the chart to a 3 year view with the rolling 12 month average based on the whole 15 year data set?
Assuming you have an AsOfMonth field like described in the blog post then you can add a set modifier to your expression(s) to select only the last three years.
I have to get an accumulated count distinct of suppliers from the very beginning of my data up to now. I already implemented the AsOf Table following Henric's method, but I struggle to get the right formula.
I also have to show in the bar chart only the year and the month selected.
hic gwassenaar how to use as-of-table for Year-to-Go (YTG) and 12-months-rolling-forecast not rolling 12 months past trend? For example, assuming calendar year as fiscal year, if I select April 2017, for YTG it gives May 2017 to Dec 2017 sales and for 12 months-Rolling-Forecast, it gives May 2017 to April 2018 sales.
How do I do to implement the As-Of Table with a Fiscal Calendar? I have my master calendar with fiscal year, exactly like this other post of Henric: Fiscal Year. Any thoughts?