Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld 2022, LIVE in Denver CO., May 16-19, 2022. REGISTER NOW TO RECEIVE EARLY BIRD PRICING
cancel
Showing results for 
Search instead for 
Did you mean: 
dhgaimez
Contributor
Contributor

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
Specialist III
Specialist III

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
pradosh_thakur
Master II
Master II

Try

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

-Pradosh

Learning never stops.
edwin
Specialist III
Specialist III

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