Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to calcualte previous Month Year column with set analysis

Greetings,

Question

I would like to create a pivot table with a column showing sales of a given month and another column showing the sales of the same month last year.

I would like to do this using expressions and not in the script.

Example

Lets say I have the following data (however there will be more dimensions like country, product etc.):

MonthYearSales
jan-12100
feb-12200
mar-12300
apr-12400
maj-12500
jun-12600
jul-12700
aug-12800
sep-12900
okt-121000
nov-121100
dec-121200
jan-131300
feb-131400
mar-131500
apr-131600
maj-131700
jun-131800
jul-131900
aug-132000
sep-132100
okt-132200
nov-132300
dec-132400

This is what I would like to create:

MonthYearSalesSales - Same month Last Year
jan-12100-
feb-12200-
mar-12300-
apr-12400-
maj-12500-
jun-12600-
jul-12700-
aug-12800-
sep-12900-
okt-121000-
nov-121100-
dec-121200-
jan-131300100
feb-131400200
mar-131500300
apr-131600400
maj-131700500
jun-131800600
jul-131900700
aug-132000800
sep-132100900
okt-1322001000
nov-1323001100
dec-1324001200

What have been tried

I have tried several variations of set analysis with the general idea being:

=sum({<MonthYearNum={$(=num(Addmonths(MonthYearNum,-12)))}>} Amount)

However, I understand why this does not work, as the Dollar sign expansion do not take the table into account.

Does someone have any suggestiona?

Thank you.

3 Replies
MarcoWedel

Hi,

as you want to do this using a pivot table, another solution could be instead:

QlikCommunity_Thread_138534_Pic1.JPG.jpg

using two calculated dimensions (year and month):

QlikCommunity_Thread_138534_Pic2.JPG.jpg

QlikCommunity_Thread_138534_Pic3.JPG.jpg

tabSales:

LOAD Date#(MonthYear,'MMM-YY') as MonthYear,

     Sales

FROM [http://community.qlik.com/thread/138534] (html, codepage is 1252, embedded labels, table is @1);

hope this helps

regards

Marco

Not applicable
Author

Dear Marco,

Thanks for taking the time to answer my question. I appreciate it.

It is a valid response given the information provided, but it is not exactly what I was looking for.

I have decided to use the AsOfTable approach (http://community.qlik.com/docs/DOC-4252) even though I at first did not want to use scripting.

Thanks again.

Best Regards

MarcoWedel

you're welcome

regards

Marco