Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Customer & Partners, DEC. 9, 11 AM ET: Qlik Product & Strategy Roadmap Session: Data Analytics REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
robynrshields
Contributor III
Contributor III

If Statements in script

I have a requirement where I'm using the following If statement in the load script.  I'd like to know if anyone has any suggestions to be more efficient.  Or is this the best way to do this?  Note that I have over 8 million records in this table.  Thanks in advance.

If( (practice = 'A' or practice = 'B') AND (Payer='1') AND ServiceDate < '01/01/2000', 'code1',
If( v75_svcSortName = 'C', 'code2'

If(( practice ='A' or practice = 'B' or practice =’D’) AND (Payer ='2') AND  ServiceDate < '01/01/2005', 'code3', ‘other’ )))  AS BillingCode

 

 

1 Solution

Accepted Solutions
maxgro
MVP
MVP

Peter, AFAIK short circuit evaluation doesn't happen in Qlik

Re: help - performance improvements

View solution in original post

12 Replies
Anil_Babu_Samineni

THis one work line charm without hang application. So, you can check without this condition and with condition how elapse time increases

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
robynrshields
Contributor III
Contributor III
Author

Can you please tell me if there another way to do instead of using 'If' statements? 

Anil_Babu_Samineni

Pick(Match()).. is alternative option. But, I don't think any performance issue using yours.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
robynrshields
Contributor III
Contributor III
Author

How can I do Pick(Match) for several fields with several conditions?

practice, Payer, v75_svcSortName, and ServiceDate must be < Date

maxgro
MVP
MVP

Don't think

Also I think that without the if the running time would decrease for a few seconds,

did you try without if?

Anil_Babu_Samineni

My question is "Why are you looking another approach". Because, If else statement are good in Script.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
robynrshields
Contributor III
Contributor III
Author

If I take the 'If' Statement out then I'll need to put into the set expression.  I'm just trying to make the script more efficient as I understand 'If' Statements can be costly within the script. 

Colin-Albert

Do you need to run the if and compare to all 8M records to calculate the BillingCode for each row everytime you load the data?

Why not look at an incremental load, where you run this script just against new or modified data and store the results to a QVD, then you are only calculating the Billing Code for new data not on all 8M records each time.

Search for "Incremental Load" and you will find many resources with example scripts.

Peter_Cammaert
Partner
Partner


[Edit: Removed useless example of non-existent optimization]


But as Massimo and Anil have already stated, you will make an effort without really knowing what your gain could possibly be. To get an idea of how much time can be save ideally, run the script without the IF()'s and then with the IF()'s and compare those delays. Contrary to what you are thinking, the load script doesn't mind that it has to run a few minutes longer. On the other hand, using nested IF()'s in the User Interface should be avoided as much as possible.