Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
aviadbein
Not applicable

If Condition for Multiple And values in expression

I All,

I'm trying to write an expression with using if statement in order to sum multiple field values.

I've got "Source" field with 2 values: Order, Invoice.

I tried the following if statement:

if(Source='Order' and Source='Invoice', sum(OrderUnits) + sum(InvoiceUnits),

  if(Source='Order', sum(OrderUnits), if(Source='Invoice', sum(InvoiceUnits))))

but I get wrong numbers.

I know that for multiple Or values I can use match(), in what function or condition can I use for multiple And values?

Thanks in advance,

Aviad

Tags (3)
1 Solution

Accepted Solutions
sunny_talwar
Not applicable

Re: If Condition for Multiple And values in expression

Or this

If(SubStringCount('|' & GetFieldSelections(Source, '|,|') & '|', '|Order|') = 1 and SubStringCount('|' & GetFieldSelections(Source, '|,|') & '|', '|Invoice|') = 1,  Sum(OrderUnits) + Sum(InvoiceUnits),

     If(Source='Order', Sum(OrderUnits),

          If(Source = 'Invoice', Sum(InvoiceUnits))))

3 Replies
sunny_talwar
Not applicable

Re: If Condition for Multiple And values in expression

Try this:

If(GetSelectedCount(Source) = 2, Sum(OrderUnits) + Sum(InvoiceUnits),

  If(Source='Order', Sum(OrderUnits),

     If(Source = 'Invoice', Sum(InvoiceUnits))))

sunny_talwar
Not applicable

Re: If Condition for Multiple And values in expression

Or this

If(SubStringCount('|' & GetFieldSelections(Source, '|,|') & '|', '|Order|') = 1 and SubStringCount('|' & GetFieldSelections(Source, '|,|') & '|', '|Invoice|') = 1,  Sum(OrderUnits) + Sum(InvoiceUnits),

     If(Source='Order', Sum(OrderUnits),

          If(Source = 'Invoice', Sum(InvoiceUnits))))

aviadbein
Not applicable

Re: If Condition for Multiple And values in expression

Hi Sunny,

Both solutions work like a charm.

However, I prefer the second solution because it's generic and suitable for cases like field with three or more values by make it possible to combine different sets of values.

Thanks for your help!