Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW

Why Is It Not A Good Idea To Use Nested If Statements?

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
ToniKautto
Employee
Employee

Why Is It Not A Good Idea To Use Nested If Statements?

Last Update:

Jan 18, 2023 1:01:10 AM

Updated By:

ToniKautto

Created date:

Jan 6, 2015 7:42:22 PM

Nested If() statements can often appear as a convenient way to implementing conditional logic. When using nested If() statements performance issues can often be observed, both related to reload and end-user interaction with application.

  • Slow reload
  • High memory consumption during reload
  • Slow sheet object update
  • Slow application performance in general
  • High memory consumption by Qlik Engine during multiple user sessions

 

Environment:

QlikView 
Qlik Sense Enterprise on Windows 
Qlik Cloud 
Qlik Sense Business 


If() function can be used in Qlik Sense or QlikView data load script and sheet object to generate conditional functionality. 

if(condition , then , else) is defined as having the three parameters conditionthen and else. Condition is interpreted logically. If condition is true, the function returns the value of the expression then. If condition is false, the function returns the value of the expression else

The Qlik Engine will always evaluate the entire If() statement. This means that both the then and else expressions are evaluated, regardless of the condition being true or false. This is an optimized behavior, based on the assumption that all results will occur at some time during the application usage or reload, and therefore it makes sense to pre-calculate and put the result in cache as soon as possible. 

In an nested If() statement the evaluation can very easily lead to a lot of calculation overhead and thereby slow down or in worst case choke Qlik Sense or QlikView execution. 


NOTE: A badly designed If() statement can in general perform slower than the alternative methods in QlikView or Qlik Sense, regardless if the statement is nested or not. 

Qlik has multiple conditional functions which can be used to accomplish the If() statement logic. 

  • Alt() 
  • Pick()
  • Match()
  • MixMatch()
  • WildMatch()

In sheet objects set analysis and set expressions can be used to accomplish conditional operations. 

In the script preceding load can be used to make conditional operations step by step, minimizing the calculation overhead. This also often makes the script easier to interpret and maintain.

The most optimal solution depends on the data structure and requirements and has to be evaluated by the QlikView or Qlik Sense Application developer from case to case. 

Labels (1)
Version history
Last update:
‎2023-01-18 01:01 AM
Updated by: