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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Pooja2
Contributor
Contributor

Pivot table Current and Previous month data for a current month

Hi, 

I am trying to create a report in qlik in below format.

where for current Month year i have to show 2 measure 1 with current month value and another with previous year same month.

But i am unable to show previous month value as a measure.

is it possible to achieve this.

kindly Help.

Pooja2_0-1688456149151.png

 

Labels (2)
1 Solution

Accepted Solutions
udit_k
Partner - Creator II
Partner - Creator II

you could nullify month in expression :-

LM:-sum({<Year={'$(=year(addyears(yearstart(max([Start Date])),-1)))'},Month={'>=$(=month(yearstart(max([Start Date]))))<=$(=month(Max([Start Date])))'},Month=>}value)

CM:-

sum({<Year={'$(=year(addyears(yearstart(max([Start Date])),0)))'},Month={'>=$(=month(yearstart(max([Start Date]))))<=$(=month(Max([Start Date])))'},Month=>}value)

 

udit_k_0-1688467835845.png

 

View solution in original post

4 Replies
udit_k
Partner - Creator II
Partner - Creator II

use below dummy data and expression calculated to get Current Month and Previous year Month:-

Load *, Year ([Start Date]) as Year,
Month([Start Date]) as Month,
Monthname([Start Date]) as Month1;
Load

* INLINE [

ID, Start Date,value
1,01/01/2023,1
1,01/01/2022,10
2,10/01/2023,20
2,10/01/2022,30
3,10/01/2023,40
3,10/01/2022,5
4,03/04/2023,10
4,03/04/2022,10
];

exit Script;

 

Current month:-

sum({<Month1={'$(=monthname(Max([Start Date])))'}>}value)

 

Previous  Year Month:-

sum({<Month1={'$(=monthname(addmonths(Max([Start Date]),-12)))'}>}value)

 

Output:-

udit_k_0-1688462113177.png

 

 

Pooja2
Contributor
Contributor
Author

this will work when you don't have MOnth_Year dimension in columns of pivot table.

I have 1 dimension in column which is year.

under current year dimension i have to show 2 measures

udit_k
Partner - Creator II
Partner - Creator II

you could nullify month in expression :-

LM:-sum({<Year={'$(=year(addyears(yearstart(max([Start Date])),-1)))'},Month={'>=$(=month(yearstart(max([Start Date]))))<=$(=month(Max([Start Date])))'},Month=>}value)

CM:-

sum({<Year={'$(=year(addyears(yearstart(max([Start Date])),0)))'},Month={'>=$(=month(yearstart(max([Start Date]))))<=$(=month(Max([Start Date])))'},Month=>}value)

 

udit_k_0-1688467835845.png

 

Pooja2
Contributor
Contributor
Author

Thanks a lot for the help.

It's working now.