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

Better alternative to nested if statement

Hi everyone,

I have a file that uses nested if statement. At the moment this is not a problem since I'm working with a small sample, but for the final version I'll need about 53 statements.


I'm using this expression in a straight table to calculate wks sup. For every week, I need to compare the current inventory to the aggregate sum of forecasts for all the weeks before.

I'm trying to find a more efficient way.

This is the code in the smaller sample:

if(sum([inventory - current])=0,0,

if(sum([inventory - current])>sum(forecast),'>year',

if(sum([inventory - current])<sum(if([calc week]<=1,forecast)),0,

if(sum([inventory - current])<sum(if([calc week]<=2,forecast)),1

,2))

))

Is there a way to rewrite this without the nested if statemets?

Thanks

1 Reply
vgutkovsky
Master II
Master II

Well, a better way would be to take a lot of the logic to the script and create flags that could then be referenced in the UI expressions. If you're determined to do it purely in the UI and just want to avoid manually typing a huge expressions, see attached.

Regards,

Vlad