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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
tcyw2910
Contributor II
Contributor II

How to use IF ELSE expression for bar charts?

Hi,

I currently have the below expression running for my bar chart, which is not a problem :

=if((Today()-[Sent Date Time])<0, '<1',
if((Today()-[Sent Date Time])> 0 and (Today()-[KCI Sent Date Time])<5, '<5',
if((Today()-[Sent Date Time])>=5 and (Today()-[KCI Sent Date Time])<10, '>5',
if((Today()-[Sent Date Time])>=10 and (Today()-[KCI Sent Date Time])<15, '>10',
if((Today()-[Sent Date Time])>=15 and (Today()-[KCI Sent Date Time])<20, '>15',
if((Today()-[Sent Date Time])>=20, '>20'))))))

However, I was wondering if I could incorporate the Else if statement to this expression, so that it doesn't run through all conditions, and ends once it's found just ONE in any condition. 

E.g. if there is data that meets the first condition, then it'll go into that first bucket, thus ending the if statement rather than continuing on.

 

Thanks,

Terence

4 Replies
jwjackso
Specialist III
Specialist III

Nope.  Why is it not a good idea to use nested IF statements. 

Qlik evaluates entire IF statement to cache the results.

tcyw2910
Contributor II
Contributor II
Author

okay thanks! That makes sense 🙂

Do you happen to know of a better alternative to using IF statements then?

jwjackso
Specialist III
Specialist III

In the link that I provided, it recommends Alt(), Pick(), Match(), MixMatch() and WildMatch() as alternatives.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You can make it simpler by testing high to low, eliminating the "and"s:

if(Today()-[Sent Date Time]) >= 20, '20'
,if(Today()-[Sent Date Time]) >= 15, '15'
,etc..

That will not eliminate the calculation of all branches, but it will make it easier to write and read.

-Rob