Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
The #1 reason QlikView customers adopt Qlik Sense is a desire for a modern BI experience. Read More
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

How if nested works?

Hi!

I am using if nested, but I am having performance problems. I would like to know how does qlikview evaluate the conditions. I mean, if the first condition is true then the other "if" conditions are not evaluated? or do all "if" conditions are evaluated always?

For example:

if(a=b,1,if(a=c,if(a=d,1,0)))

desired behaviour:

If a=b -> True, then qlikview returns 1 and ignores the other "if" statements. Is this the real behaviour?

Please help me to understand!

Thank you.

Linda

16 Replies
Highlighted
Specialist III
Specialist III

Re: How if nested works?

I suggest you painting a simple image:

Screenshot_3.jpg

Then follow up the path according your conditions.




Highlighted
MVP & Luminary
MVP & Luminary

Re: How if nested works?

Nested if-constructs are a performance-killer! I'm not absolutely sure but I believe that at first all branches of a nested-if-loop will be calculated and the evaluation which part is true comes at the last step.

Therefore is often better to use other techniques for this, for example the pick(match()) and/or alt or with a mapping or maybe set analysis. It will depend on your concrete scenario which (kind or combination of methods) suits best whereby in your case you could also use:

if(a=b or a=c or a=d, 1, 0)

or here another example:

alt(pick(match(a, 'b', 'c', 'd'), 1, 1, 1), 0)

- Marcus

Highlighted

Re: How if nested works?

Hi,

I have experience such issue.

Yes I agree with you, that first all branches of nested if else loop calculated and because of that we face so much performance issue.


Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Highlighted
Not applicable

Re: How if nested works?

I see... Thank you Marcus... I have another question please, My if conditions are made with the following structure: if (a>0, 1, 0) ...how can I replicate it with pick/Match? , is it possible? ..or pick/match only works with equal "="?.

Thank you.

Highlighted
Not applicable

Re: How if nested works?

Thank you Max! ...how did you solve your problem?

Highlighted
MVP & Luminary
MVP & Luminary

Re: How if nested works?

Please give a more practical example and some more details to where do you want to use it with which aim (script/gui, more fields included, as flag, ...?).

- Marcus

Highlighted

Re: How if nested works?

Hi,

depends on requirement. Most of the time set analysis help me to resolve such issue.

Some time I have create flag in script or modify script.

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Highlighted
Not applicable

Re: How if nested works?

I am using it on a variable which is called and executed from an object in gui (indicator).

I have changed "if nested" into "or", but I still have performance problems:

Details:

$variable code:

if(

a>0 or

b>0 or

c>0 or

...(500 comparisons more)

z>0 ,1,0)


indicator expression:

if($variable>0,1,0)


I have 13 indicators with the same logic on a sheet. The problem is that the sheet takes 15 minutes to refresh and show the objects. (performance problem)


I am thinking that perhaps objects(indicator) does not support too much operations (execution of lines of code). What do you think?

Highlighted
MVP & Luminary
MVP & Luminary

Re: How if nested works?

I think an expression which makes more than 500 comparisations will be always perform very poorly. Therefore I think you will need a different approach by simplifying some of the parts by precalculating some parts within the script, creating clusters for your a,b,c ... and something more.

Like above mentioned you need to provide more details. If a,b,c are different fields or variables or expressions? Where should it be used - chart-type, textbox, .... which dimensions are included? What is the end-aim of it - delivering 0 or 1 is probably only an intermediate step?

- Marcus