Qlik Community

QlikView Deployment

Discussion Board for collaboration related to QlikView Deployment.

kirsten_dc
New Contributor II

If with one condition and multiple expressions

Dear community,

is there any possibility to create an if-statement with only one condition but multiple expressions?

I need to load a table with these information in my script.

Simple exmple:

if(IsNull(A),B and C)

If my idea isn't practicable are there any other possibilities to get two results at once using only one condition?

Regards,

Kirsten

1 Solution

Accepted Solutions

Re: If with one condition and multiple expressions

A resident table (the end result of any script LOAD) can store either one (number or text with corresponding representation) or two values (dual() where string and number don't need to correspond but they do have a very strict relation) in every column cell. The most common (and most simple) method is to store a single expression result in a single cell.

If your outcome of the IF-true expression can be stored as a single value (either by concatenating B to C, like Sunny suggested, or by simply performing B + C to get a single number) then yes, you can use a single IF function evaluation.

If not, you'll have to create separate columns and repeat the same IF clause in every column expression. Don't worry, this is common practice.

If the IF function is too complex to repeat in a maintainable state, store the outcome of the IF function in a temporary Flag field, and use that Flag field in a Preceding LOAD that immediately follows to calculate the different column values, like:

MyTable:

LOAD IF (Flag = 1, B) AS ColumnB,

     IF (Flag = 1, C) AS ColumnC,

     : // other fields

     ; // Terminate preceding LOAD

LOAD IF (This and that but not those and omit these while excluding the others and in case of an exception accept everything, 1, 0) AS Flag,

     : // other fields

FROM ExternalSourceFile (options);

That way you'll have to repeat the complex IF clause only once.

Peter

3 Replies

Re: If with one condition and multiple expressions

On what condition what you are trying to achieve? can you elaborate a bit more

Re: If with one condition and multiple expressions

Not sure what you want to see, but may be this:

If(IsNull(A), B & ' ' & C) as NewCol

Re: If with one condition and multiple expressions

A resident table (the end result of any script LOAD) can store either one (number or text with corresponding representation) or two values (dual() where string and number don't need to correspond but they do have a very strict relation) in every column cell. The most common (and most simple) method is to store a single expression result in a single cell.

If your outcome of the IF-true expression can be stored as a single value (either by concatenating B to C, like Sunny suggested, or by simply performing B + C to get a single number) then yes, you can use a single IF function evaluation.

If not, you'll have to create separate columns and repeat the same IF clause in every column expression. Don't worry, this is common practice.

If the IF function is too complex to repeat in a maintainable state, store the outcome of the IF function in a temporary Flag field, and use that Flag field in a Preceding LOAD that immediately follows to calculate the different column values, like:

MyTable:

LOAD IF (Flag = 1, B) AS ColumnB,

     IF (Flag = 1, C) AS ColumnC,

     : // other fields

     ; // Terminate preceding LOAD

LOAD IF (This and that but not those and omit these while excluding the others and in case of an exception accept everything, 1, 0) AS Flag,

     : // other fields

FROM ExternalSourceFile (options);

That way you'll have to repeat the complex IF clause only once.

Peter

Community Browser