Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to avoid nested if

I have an expression that is essentially:

if exp1 is not null then

exp1

else

exp2;

if exp2 is not null then

exp2

else

exp3;

etc...

if expn is not null then

expn

else

'Unknown';

I can't do this in the load statement because each of these expressions are based off of user input.  Essentially, I have a hierarchy classifications.  A record could have a value for several different sources of classifications and the user can change their hierarchy (preferred order of classifications) for all securities.  Some securities may only have classifications from a classification source that the user does not select, which is the reason for the 'Unknown' at the end of the nested if.  I'm hoping there is a better way to do this process in QV as it will be pervasive across many reports and I expect would hit performance.  Any suggestions would be greatly appreciated.

9 Replies
marcus_sommer

You could try it with the function alt().

- Marcus

ThornOfCrowns
Specialist II
Specialist II

This: http://community.qlik.com/docs/DOC-5841 might help, hopefully.

Not applicable
Author

That link says at the end that the speed compared to a nested if was not any different.  Is my assumption that nested ifs are big hits to performance?

marcus_sommer

If-Statements are always slow. But you could try it with conditions on the expressions - this means you have no nested if then only the expression(s) with a valid condition will be displayed.

- Marcus

Clever_Anjos
Employee
Employee

alt(exp1,exp2,exp3,exp4,'Unknow')

Not applicable
Author

does alt only work on numbers?

Clever_Anjos
Employee
Employee

Yes

Not applicable
Author

Is alt significantly faster than a nested if?  I can probably convert the field i'm working with to duals, allowing alt to work on them but return the strings I need.

Clever_Anjos
Employee
Employee

I´ve never tested speed of both.

I generally use it because is much 'cleaner' to read and mantain