Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Comparing dates and using an if statement

Hi there,

I am trying to compare today's date to see if it falls within our period quarter and if the period quarter is in the past, I want to do another calculation instead. I think that the date comparison is incorrect in my code but I can't figure out what I am doing wrong. So, I have made sure that the date I am comparing is set up as a Date in the format 'YYYYMMDD'

=if(date(today(0),'YYYYMMDD')<[Period Quarter End Date], Calc1,Calc2)

Could you please tell me where I am going wrong?

Thanks, Mike

1 Solution

Accepted Solutions
Not applicable
Author

Thanks for all the help, unfortunately, I cannot use the InQuarter function as we are using our periodic months, not calendar months.

I found out that the data has multiple period end dates so a simple date#([Period Quarter End Date],'YYYYMMDD') produces a null value so I used

=if(date(today(0),'YYYYMMDD') < date(max({$<[Period Quarter]={'Q1'}>}[Period Quarter End Date]),'YYYYMMDD'), calc1,calc2)

Hope this helps other people.

Mike



View solution in original post

3 Replies
Not applicable
Author

Hi,

please provide some data.

Thank you!

Rainer

Miguel_Angel_Baeyens

Hello Mike,

It should be as simple as:

=if(date#(today(0),'YYYYMMDD') < date#([Period Quarter End Date],'YYYYMMDD'), Calc1, Calc2)


Note the date#() function instead the date() function to force comparing to a timestamp.

But I'd suggest you to use a different function:

=if(InQuarter(Today(),date([Period Quarter End Date]),0), Calc1, Calc2)


Hope this helps.

Not applicable
Author

Thanks for all the help, unfortunately, I cannot use the InQuarter function as we are using our periodic months, not calendar months.

I found out that the data has multiple period end dates so a simple date#([Period Quarter End Date],'YYYYMMDD') produces a null value so I used

=if(date(today(0),'YYYYMMDD') < date(max({$<[Period Quarter]={'Q1'}>}[Period Quarter End Date]),'YYYYMMDD'), calc1,calc2)

Hope this helps other people.

Mike