Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Show previous 12 months of different years

Hey,

I have a question concerning comparing different months.

I have one dimension shown: Month

I managed to create a table in which I can compare one month with a previous one (even if it is the previous year):

sum({$<Year={$(=Year(AddMonths(MakeDate(Only(Year), only(Month), 1), -1)))},Month={$(=month(AddMonths(MakeDate(Only(Year), only(Month), 1), -1)))}>}Sales)

With this I can compare eg. January 2013 with December 2012 (even if it is in another year).

What I want to do now is show 13 months for my comparison: the selected month and year and all the previous 12 months.

If I select August 2013, I want to see August 2012, September 2012, October 2012, November 2012, December 2012, January 2013, ... till August 2013.

I managed to do this with this expression:

=(sum({$<Month={">=$(=Date(AddMonths(Max(Month), -13))) <=$(=Date(addMonths(Max(Month), 0)))"}>}Sales))

The problem: I cannot show the previous 12 or 13 months when they are in a different year. See graph below: the selected month is September, and it only shows me until January..

I have the two expressions, I just don't seem to manage to combine them..

Please who can help me out?

Cheers,

Zipke

Knipsel.JPG

1 Solution

Accepted Solutions
Not applicable
Author

Hi guys,

I found my own solution !! I had to show all of the Months and Years, in order to show the selection I wanted. The expression below shows 13 months. The selected month + the 12 months before the selected one.

Even if the months are of different years.

=(sum(Year=, Month=, MonthYear={">=$(=Date(addmonths(Max(MonthYear), -12), 'MMM-YY')) <=$(=Date(addmonths(Max(MonthYear), 0),  'MMM-YY'))"} >}Sales))

Cheers

View solution in original post

2 Replies
Not applicable
Author

Is it not possible with just expressions and dimensions?

I prefer not to touch the script to be honest.. It feels like I have got both parts already, I just need to merge them together..?

Not applicable
Author

Hi guys,

I found my own solution !! I had to show all of the Months and Years, in order to show the selection I wanted. The expression below shows 13 months. The selected month + the 12 months before the selected one.

Even if the months are of different years.

=(sum(Year=, Month=, MonthYear={">=$(=Date(addmonths(Max(MonthYear), -12), 'MMM-YY')) <=$(=Date(addmonths(Max(MonthYear), 0),  'MMM-YY'))"} >}Sales))

Cheers