Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
johnca
Specialist
Specialist

If - Then - ElseIf - EndIf in Script

I'm trying to figure out if this is even possible. I haven't had any luck on my own using the following routine and any similar. I'm trying to apply logic on a resident table and make field values based on the initial logic. I realize the following is probably not syntactically correct. Assume the variables are valued values.

Anything like this possible without loading the resident table 3x to get the desired result?

Summary_Data:

NoConcatenate

LOAD

If

     Country = 'US'

     and Date >= '$(vStartOneDate)'

     and Date <= '$(vTableOneDate)'

Then

     Product,

     App,

     Country,

     'One' as Source_Table

Else If

     Country = 'US'

     and Date >= '$(vStartTwoDate)'

     and Date <= '$(vTableTwoDate)'

Then

     Product,

     App,

     Country,

     'Two' as Source_Table

Else If

     Country = 'US'

     and Date >= '$(vStartThreeDate)'

     and Date <= '$(vTableThreeDate)'

Then

     Product,

     App,

     Country,

     'Three' as Source_Table

End If

Resident Detailed_Data;

11 Replies
johnca
Specialist
Specialist
Author

Thanks Sunny, that's kind of what we figured, but still wanted another set of eyes. Now 15 minutes per run or 45 total. I have seen longer as you've mentioned. It's still faster than having it in the users' front end.

I'm not certain of the number of rows in the source table (this is a contemporary's project) but I believe it is in the 10's of million of rows. The source table is created reading a database on a daily basis.


I (and my cohort) appreciate the thought provided.


John

Peter_Cammaert
Partner - Champion III
Partner - Champion III

You could start by trying to remove the IF functions from the Count() aggregation functions. Since you're reading everything from an internal table, it would be better to create field copies that have their value set to NULL if the condition xxx<=0 is fulfilled during the initial LOAD.

Another thought: set one of three flags to 0/1 if the condition is fulfilled, and use Sum() instead of Count() to create the counts. Sum() is way faster than Count(). However the DISTINCT keyword may force you to create a complex version of this simple expression.