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

Current Year vs Previous Year Sort Order

Hi All,

I've Googled endlessly but seem unable to find a solution to my issue.

I have a table which holds records with a date field.  I am using the QlikView Components qvs to generate my "master calendar" from the date field (CaseDate).

The user can select Year, Month and Day to filter the various charts/tables on the report.

However, I want one chart to show a sum of figures based on the max date the person selects.  The chart should show the 12 months leading up to the selected date as the CY and the 12 months prior to that as the PY.

For example, if the user selects Year=2017, Month=Feb then I want the following data:

Current Year = Total records Mar-2016 to Feb-2017

Previous Year = Total records Mar-2015 to Feb-2016

Now, I can get this information using a Set Analysis but if I just return the month name then I can't get it to sort with Mar first and Feb last.  If I return the year to sort then I get 24 records rather than 12:

   

CaseYear-MonthCYPY
2015-Mar0210
2015-Apr0171
2015-May0189
2015-Jun0244
2015-Jul0228
2015-Aug0169
2015-Sep0224
2015-Oct0224
2015-Nov0222
2015-Dec0183
2016-Jan0210
2016-Feb0243
2016-Mar2130
2016-Apr2040
2016-May2020
2016-Jun2120
2016-Jul2180
2016-Aug1960
2016-Sep2230
2016-Oct1970
2016-Nov2260
2016-Dec1740
2017-Jan2160
2017-Feb207

0

I've attached a screenshot to try and show the issue.

Can anyone point me in the right direction?

Many thanks,

Phil

23 Replies
adamdavi3s
Master
Master

Inspired sir!!

Frank_Hartmann
Master II
Master II

but without your piece of code i would try untill tomorrow.

i recently had a similar problem and swuehl gave me the final advice with mod function.

Just had to transform his solution to the actual problem 🙂

sunny_talwar

This is what I love about this community, we work together to get better solutions and help each other learn while helping others

Not applicable
Author

What an amazing community!  My first post and I never expected such swift and helpful responses.

=Mod(Only({1}MonthName)-Min(TOTAL MonthName+1),12)+1 worked perfectly for me.  Now to research in to how it works to understand it better

Thanks again to you all!