A week or two ago I had a request for how to create visualizations that leveraged rolling dates. For example, show the event count for the last 4 weeks (rather than specifically filtering on the last four specific weeks of the year). My teammate Wayne Johnson referred me to some documentation on how to modify your Mondrian schema file to enable this capability in Pentaho Analyzer, and it took me a while to really figure out how to get it to work, so I thought I’d share an example that I was successful with.
First, the goal. For this test data set, I wanted to be able to show something like the image below, and have it be correctly up to date each day to show only the prior four days.
So how did I get there? Have a look at the Mondrian schema file:
The key to getting this to work is matching up the annotation format from each dimension level with the values from the date/time dimension table. In this case, the values from my date dimension looked like this:
As such, I had to provide some string literals within the “AnalyzerDateFormat” annotation and use the year for every level. For example, ‘[yyyy].['Q'q yyyy].[MMM yyyy]‘ matches the year, quarter, and month format. ’[yyyy]‘ is clearly the year format, but the ‘quarter_desc’ column in the dim_date table held values that were non-standard according to the documented formatting rules. The ‘Q’ in ‘['Q'q yyyy]‘ matches directly with the data, whereas the ‘q’ matches with the numeric quarter (1 in the graphic above).
Once I figured out how to configure the format strings, all I had to do was make use of the newly available filtering option for dates. After right clicking on “Date” and choosing “Filter”, now I can “choose a commonly used time period” and select a specific number of previous dates (in this case 25, because my data is a little bit old).
If I set my system clock forward a day and re-run the report, we see that the report automatically updates (in this case showing only three days worth of data):
Hopefully this is helpful!