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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
dhgaimez
Contributor II
Contributor II

YearMonth if statement

Hey all,

I am trying to use an if statement using YearMonth in relation to a calculated value and cannot get it working.

This is working
if(YearMonth = '2020-02',0,1)

Trying to get something like this to work. 
if(YearMonth = Date(AddMonths(max(YearMonth), -6),'YYYY-MM'), 0, 1)

Date(AddMonths(max(YearMonth), -6),'YYYY-MM') outputs 2020-02

Can't figure out why this wouldn't work. Any help is appreciated!

4 Replies
edwin
Master II
Master II

it looks like you are comparing two different types, make both dates in your compare

MayilVahanan

Hi @dhgaimez 

Try with variable for this . 

ex:

vpast6Month = Date(AddMonths(max(YearMonth), -6),'YYYY-MM')

if(YearMonth = '$(vpast6Month)',0,1)

Hope it helps

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
pradosh_thakur
Master II
Master II

Try

if(YearMonth = text(Date(AddMonths(max(YearMonth), -6),'YYYY-MM')), 0, 1)

-Pradosh

Learning never stops.
edwin
Master II
Master II

as i said both side of the equation should have same data type convert both to date:

if(date(YearMonth&'-01') = AddMonths(date(max(YearMonth)&'-01'), -6), 0, 1)

you dont need the formatting to YYYY-MM