Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
business_intelligence
Contributor III
Contributor III

Previous Year Month Variable

I have a variable for the previous month that works every other month but for this month it's returning 202300 and I want it to return 202212. 

My current variable is:

=max((Cal.YearMonth)-1)

Is there a better way to do this?

Labels (1)
1 Solution

Accepted Solutions
ogster1974
Partner - Master II
Partner - Master II

Assuming you have a standard calendar with dates try

=Date(addmonths(max(Date) ,- 1)),'YYYYMM')

 

 

 

View solution in original post

3 Replies
ogster1974
Partner - Master II
Partner - Master II

Assuming you have a standard calendar with dates try

=Date(addmonths(max(Date) ,- 1)),'YYYYMM')

 

 

 

QFabian
Specialist III
Specialist III

HI, maybe try this.

//Create some data :

SET DateFormat='D/M/YYYY';

Cal.YearMonth:
Load * INLINE [
Cal.YearMonth
202211
202212
202301
];

Load
Cal.YearMonth,
monthname(MAKEDATE(LEFT(Cal.YearMonth,4), RIGHT(Cal.YearMonth,2))) as Date
Resident Cal.YearMonth;

DROP TABLE Cal.YearMonth;

exit script;

 

// Then in the variable editor create my variable 

QFabian_1-1672937307257.png

vPreviousYearMonth = monthname(addmonths(Date, -1))

 

// and then use it, selecting a period.

QFabian_3-1672937410758.png

 

 

 

QFabian
business_intelligence
Contributor III
Contributor III
Author

This worked! Thank you