Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

toedegaard
New Contributor II

IF Statement inside Set Analysis

Hi all,

I want my expression to show the sales amount of the latest month if no months are selected (Field: DW_SK_Date). However, if one or multiple months are selected the expression has to show the selected months.

I have a field (IsCurrent) that specifies if it is the latest month (ISCurrent=1) or not (ISCurrent=0).

I have tried to make a variable with the IF Statement and then put it into a set expression (see below), but it does not work.

Can someone please help me out?

Variable: vISCurrent = IF(GetSelectedCount(DW_SK_Date)=0,1,0)

Set Expression: Sum({<IsCurrent={$(vISCurrent)}>}Amount)

Please see my test dataset attached

Kind Regards,

Thomas

1 Solution

Accepted Solutions
MVP
MVP

Re: IF Statement inside Set Analysis

How about this?

Sum({<IsCurrent={$(=If(GetSelectedCount(DW_SK_Date)=0,1,0))}>}Amount)

6 Replies
MVP
MVP

Re: IF Statement inside Set Analysis

Try this may be

Sum({<IsCurrent={$(=vISCurrent)}>}Amount)

toedegaard
New Contributor II

Re: IF Statement inside Set Analysis

Still does not work, unfortunately

MVP
MVP

Re: IF Statement inside Set Analysis

How about this?

Sum({<IsCurrent={$(=If(GetSelectedCount(DW_SK_Date)=0,1,0))}>}Amount)

toedegaard
New Contributor II

Re: IF Statement inside Set Analysis

That seems to work. Thanks!

Do you know why it does not work with a variable? Or what I can do to put it into a variable, as I will have to make this calculation in several other expressions?

MVP
MVP

Re: IF Statement inside Set Analysis

Does you variable include the = sign or not?

=If(GetSelectedCount(DW_SK_Date)=0,1,0)

Try adding or removing it and see if that makes any difference?

toedegaard
New Contributor II

Re: IF Statement inside Set Analysis

You're right.

It removes the equal sign in front of the variable if I am typing the expression in the expression editor (fx), however if I type it directly in the definition dialog box it keeps it - Weird

Anyway, thanks a lot for your help.