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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
arnoqlik
Contributor III
Contributor III

Store Today(1) into a variable

Hello,

At first I need to set the last day of the previous month:

 

LET vTODAY = Date(monthsstart(1, today(1))-1,'DD/MM/YYYY');

 

Then I need to remove one month if we are in January else keep the month as it is:

 

LET vYearFile = If(Num(Month($(vTODAY))) = 1, AddYears($(vTODAY), -1), Year($(vTODAY)));

 

I get 1899...

What's wrong with this code? Thank you guys!

1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

LET vYearFile = If(Num(Month($(#vTODAY))) = 1, Year(AddYears($(#vTODAY), -1)), Year($(#vTODAY)));

View solution in original post

3 Replies
stevejoyce
Specialist II
Specialist II

LET vYearFile = If(Num(Month($(#vTODAY))) = 1, Year(AddYears($(#vTODAY), -1)), Year($(#vTODAY)));

MayilVahanan

Hi

Try like below

LET vTODAY = Date(monthsstart(1, today(1))-1,'DD/MM/YYYY');
LET vYearFile = If(Num(Month(vTODAY)) = 1, AddYears(vTODAY, -1), Year(vTODAY));

vYearFile gives 2021

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
arnoqlik
Contributor III
Contributor III
Author

Thanks, both solutions are working fine.