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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If condition within Set analysis

Hi,

we face the following problem:

Count({<closed_year={"$(=Date(Date#(Year(today()),'YYYY'),'YYYY'))"}>} DISTINCT ID) is working fine, but we need to add an if-statement within the set analysis.

If Month=January it should be  (Date#(Year(today()),'YYYY')-1 ==> the year before; but how does the syntax work?

Thank you in advance!

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

if(Month='January',Count({<closed_year={"$(=Date(Date#(Year(today()),'YYYY')-1,'YYYY'))"}>} DISTINCT ID),Count({<closed_year={"$(=Date(Date#(Year(today()),'YYYY'),'YYYY'))"}>} DISTINCT ID) )

View solution in original post

2 Replies
Not applicable
Author

Hi Corinna,

I would recommend creating a variable which does the if statement and results in the correct end value. You can then use that variable in your set analysis

something like

create vDate variable

=If(Month(today())='Jan',Date#(Year(today()),'YYYY')-1, Date#(Year(today()),'YYYY'))

Count({<closed_year={"$(vDate"}>} DISTINCT ID)

just keeps your expression cleaner and means you can reuse the same variable for other expressions

Hope that helps

Joe

Not applicable
Author

Hi,

if(Month='January',Count({<closed_year={"$(=Date(Date#(Year(today()),'YYYY')-1,'YYYY'))"}>} DISTINCT ID),Count({<closed_year={"$(=Date(Date#(Year(today()),'YYYY'),'YYYY'))"}>} DISTINCT ID) )