Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
robynrshields
New 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

 

 

Tags (1)
1 Solution

Accepted Solutions
MVP
MVP

Re: If Statements in script

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

Re: help - performance improvements

12 Replies

Re: If Statements in script

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

Life is so rich, and we need to respect to the life !!!
robynrshields
New Contributor III

Re: If Statements in script

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

Re: If Statements in script

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

Life is so rich, and we need to respect to the life !!!
robynrshields
New Contributor III

Re: If Statements in script

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

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

MVP
MVP

Re: If Statements in script

Don't think

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

did you try without if?

Re: If Statements in script

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

Life is so rich, and we need to respect to the life !!!
robynrshields
New Contributor III

Re: If Statements in script

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. 

Re: If Statements in script

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.

Re: If Statements in script


[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.

Community Browser