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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
aswinnar
Partner - Contributor III
Partner - Contributor III

Current Month Jan to Previous Month Dec

Hi All, 

I am having a requirement where I need to place values for current month vs previous month 

 

 

FIELD1Date (Year month format)
A202009
B202010
C202011
D202012
E202101


I have variable set for value in current month, however I am not able to create a proper expression for getting the values from the pervious Year Month. Mainly because of Jan to Dec. If I use 202101 as current Year Month for example, I am getting 202100 as Previous Year Month Date. What expression can I use for when current year month is 202101, the previous year month date will show as 202012? 

Labels (1)
2 Replies
Vegar
MVP
MVP

By the looks of it your date field is not a date, but an integer. Therfore you can not use date funtions like addmonth() on it without manipulating it a bit. Try something like this to get prev month. 

Num(Text(Date(Addmonths(date#([Date Field], 'YYYYMM'), - 1), 'YYYYMM'))) 

bhavyagrb
Partner - Contributor II
Partner - Contributor II

Hello,

Hope this helps you!!

In Frontend  Expression:

=date(Addmonths(date#([Date(Year month format)], 'YYYYMM'), - 1),'YYYYMM')

 

Regards,

Bhavya