Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Not applicable

If then Else

Hi I am getting an expression error for this

if [ALCOHOL_Every.day] not like 'NA' then

[ALCOHOL_Every.day]

else 1=1

end if

What am I doing wrong here.

The values of ALCOHOL_Every.day ranges from 0 to 10 and I am seeing the extra value NA which I want to remove. What am I doing wrong in this ?

Thanks

Aj

1 Solution

Accepted Solutions
MVP
MVP

Re: If then Else

There are multiple things to consider:

a) If..Then... Else..End if are control flow statements you can use in the script (not in the front end), but if you are using them in the script, you can't use them within a LOAD statement. Hence you can't really use a field like [ALCOHOL_Every.day] in the if condition.

b) If you want to negate a boolean, something like FIELD LIKE 'NA', you need to write NOT FIELD LIKE 'NA'

c) I don't really understand what 1=1 in your ELSE branch is made for.

So, depending where you want to remove the value 'NA', try something like this in the script:

LOAD

     If([ALCOHOL_Every.day] <> 'NA', [ALCOHOL_Every.day] ) as [ALCOHOL_Every.day],

     ...

or maybe (if you want to remove the complete record:

LOAD

     [ALCOHOL_Every.day],

     ...

FROM ...

WHERE [ALCOHOL_Every.day] <> 'NA';


In the front end, you can either use a calculated dimension like

= If([ALCOHOL_Every.day] <> 'NA', [ALCOHOL_Every.day] )

or set analysis in all your aggregations:

=Sum({<[ALCOHOL_Every.day] -= {'NA'}>} Value)

3 Replies
MVP
MVP

Re: If then Else

Is this for a dimension? May be try this:

If([ALCOHOL_Every.day] <> 'NA', [ALCOHOL_Every.day], 1)

MVP
MVP

Re: If then Else

There are multiple things to consider:

a) If..Then... Else..End if are control flow statements you can use in the script (not in the front end), but if you are using them in the script, you can't use them within a LOAD statement. Hence you can't really use a field like [ALCOHOL_Every.day] in the if condition.

b) If you want to negate a boolean, something like FIELD LIKE 'NA', you need to write NOT FIELD LIKE 'NA'

c) I don't really understand what 1=1 in your ELSE branch is made for.

So, depending where you want to remove the value 'NA', try something like this in the script:

LOAD

     If([ALCOHOL_Every.day] <> 'NA', [ALCOHOL_Every.day] ) as [ALCOHOL_Every.day],

     ...

or maybe (if you want to remove the complete record:

LOAD

     [ALCOHOL_Every.day],

     ...

FROM ...

WHERE [ALCOHOL_Every.day] <> 'NA';


In the front end, you can either use a calculated dimension like

= If([ALCOHOL_Every.day] <> 'NA', [ALCOHOL_Every.day] )

or set analysis in all your aggregations:

=Sum({<[ALCOHOL_Every.day] -= {'NA'}>} Value)

Not applicable

Re: If then Else

Thanks Sunny / Swuehl,

I used the where clause to filter NA.

LOAD

     [ALCOHOL_Every.day],

     ...

FROM ...

WHERE [ALCOHOL_Every.day] <> 'NA';

Community Browser