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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If-else statement in LOAD

Hi,

i'm trying to to create if-else in LOAD in script level.

LOAD
ID,
(A+B+C) as F1;
SQL SELECT *
FROM TABLE

the if-else would be placed at the calculation,

column F1 = if (a+b+c) > 20 then set F1 as DIGIT 1 else 0 so that i can use it to count.

Column F2 = if (a+b+c) < 20 then set F2 as DIGIT 1 else 0....

so in the end, i'd have 3 column, ID, F1, F2



5 Replies
Not applicable
Author

Hi

Try the following


LOAD
ID,
IF(A+B+C > 20 , 1 , 0) AS F1,
IF(A+B+C < 20 , 1, 0) AS F2;
SQL SELECT * FROM TABLE;


Not applicable
Author

LOAD
ID,
if ((A+B+C)>20,1) as F1,
if ((A+B+C)<20,1) as F2;
SQL SELECT *
FROM TABLE;

/Michael

Not applicable
Author

Thanks for the solution, it works for me.

But it wont work if i'm using the new name after the AS

Load
Field1 as Fieldtext
if (Fieldtext = abc, .........

i had to use...Field1 instead of Fieldtext. any idea why?

Load
Field1 as Fieldtext
if (Field1 = abc, .........

the reason is that Field1 could be a very long formula or IF ELSE statment, so it'd be good if i can just use Fieldtext as a substitute..





Not applicable
Author

If FieldName is a long field or a formula you can replace it by a variable such as

LET MyFieldName='LongFieldNameBlablabla';

Thenin your Load

LOAD

IF("$(MyFieldName)" = abc, ....) then it should work.

Rgds,

Sébastien

rbecher
MVP
MVP

You can stack LOAD statements like this:

tablename:
LOAD Field3;
LOAD if(Field2 = 'def', ...) as Field3;
LOAD if(Field1 = 'abc', ...) as Field2 FROM....;


- Ralf

Data & AI Engineer at Orionbelt.ai - a GenAI Semantic Layer Venture, Inventor of Astrato Engine