Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
khajafareed
Contributor III
Contributor III

Last Two Months data on selection of Month

Hi,

I'm facing issue while trying to show last two month results on selection of any month in Straight Table.

I have declared below variables:

VCurrentMonthM2:

=if((vMax2)=1,'Jan',

if((

vMax2)=2,'Feb',

if((

vMax2)=3,'Mar',

if((

vMax2)=4,'Apr',

if((

vMax2)=5,'May',

if((

vMax2)=6,'Jun',

if((

vMax2)=7,'Jul',

if((

vMax2)=8,'Aug',

if((

vMax2)=9,'Sep',

if((

vMax2)=10,'Oct',

if((

vMax2)=11,'Nov',

if((

vMax2)=12,'Dec',

''))))))))))))

VCurrentMonthM1:

=month(date(monthname(Date(if(isnull(GetFieldSelections(CommonMonth)),'  ' ,max(CommonDate))))-1))

VMax2:

=if(isnull(GetFieldSelections(CommonMonth)),'',month(max(CommonDate))-2)

In Label i used: =vCurrentMonthM2&' ' &year&' '& 'Transactions Handled' 

and Expression for label is:

Count({$<[Common Ticket Type]={'INCIDENT'},[Common U_Cancelled] ={'-1'},CommonYear=,CommonMonth={$(vCurrentMonthM2)},CommonDays=,  [Common Priority]={'Priority-1'},  [Common Report_Customer]={'-1'},[Common Category_filter]={'-1'},[Common Summary_filter]={'-1'},  ResolvedTicket.isTicketOpen={'0'}>}ResolvedTicket.TicketID)

When i am selecting Dec Month i can see Previous 2 month Nov and Oct months Data.

Issue is when i am selecting Jan Month for year 2018 then i am able to see only Previous month Data i.e, Dec 2017 and not getting Nov Month's Data.

1 Solution

Accepted Solutions
YoussefBelloum
Champion
Champion

ok so you can simply do this:

1. If don't already have Master Calendar with MonthYear field, Create a MonthYear field (MMYYYY format)

2. use this set analysis part (to replace it on your expression)

{< MonthYear={">=$(=Date(AddMonths(Date#(MonthYear,'MMYYYY'),-2),'MMYYYY'))<=$(=Date(Date#(MonthYear,'MMYYYY'),'MMYYYY'))" }>}


you will have this:


Count({$<[Common Ticket Type]={'INCIDENT'},[Common U_Cancelled] ={'-1'},CommonYear=,MonthYear={< MonthYear={">=$(=Date(AddMonths(Date#(MonthYear,'MMYYYY'),-2),'MMYYYY'))<=$(=Date(Date#(MonthYear,'MMYYYY'),'MMYYYY'))" }>} ,CommonDays=,  [Common Priority]={'Priority-1'},  [Common Report_Customer]={'-1'},[Common Category_filter]={'-1'},[Common Summary_filter]={'-1'},  ResolvedTicket.isTicketOpen={'0'}>}ResolvedTicket.TicketID)


View solution in original post

3 Replies
YoussefBelloum
Champion
Champion

Hi,

did you created all this to be able to get back two months ? I Mean all this approach is created specifically only to get back two months ?

Because you have Addmonths() function which is easier in this case.

khajafareed
Contributor III
Contributor III
Author

Yeah, I need to get back two months based on current selection of Month.

YoussefBelloum
Champion
Champion

ok so you can simply do this:

1. If don't already have Master Calendar with MonthYear field, Create a MonthYear field (MMYYYY format)

2. use this set analysis part (to replace it on your expression)

{< MonthYear={">=$(=Date(AddMonths(Date#(MonthYear,'MMYYYY'),-2),'MMYYYY'))<=$(=Date(Date#(MonthYear,'MMYYYY'),'MMYYYY'))" }>}


you will have this:


Count({$<[Common Ticket Type]={'INCIDENT'},[Common U_Cancelled] ={'-1'},CommonYear=,MonthYear={< MonthYear={">=$(=Date(AddMonths(Date#(MonthYear,'MMYYYY'),-2),'MMYYYY'))<=$(=Date(Date#(MonthYear,'MMYYYY'),'MMYYYY'))" }>} ,CommonDays=,  [Common Priority]={'Priority-1'},  [Common Report_Customer]={'-1'},[Common Category_filter]={'-1'},[Common Summary_filter]={'-1'},  ResolvedTicket.isTicketOpen={'0'}>}ResolvedTicket.TicketID)