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

Announcements
Learn how to migrate to Qlik Cloud Analytics™: On-Demand Briefing!
cancel
Showing results for 
Search instead for 
Did you mean: 
jduenyas
Specialist
Specialist

OR in set analysis


Greetings all

How can I 'OR' expressions in set analysis?

How can I convert the following to a set analysis expression?

=SUM(If((FieldA = value1 AND FieldB = value2) OR (FieldA = value3 AND FieldC = value4), VALUE_TO_SUM, 0))

Normally anything within the curly braces is "AND" so how do I introduce the "OR"?

=SUM({<FieldA = {value1}, FieldB = {value2} ....... ? >}VALUE_TO_SUM)

Thanks

Josh

1 Solution

Accepted Solutions
jaimeaguilar
Partner - Specialist II
Partner - Specialist II

Hi,

you can add both expressions within a single set analysis, like this:

=Sum({$<FieldA = {'Value1'}, FieldB={'Value2'}>+<FieldA={'Value3'}, FieldB={'Value4'}>} FieldName)

so you will get:

  1. Coincidences of value1 in FieldA AND value2 in FieldB
  2. Plus coincidences of Value3 in FieldA AND value4 in fieldB

in other words you will get either 1 OR 2

Regards

View solution in original post

4 Replies
Anonymous
Not applicable

Hi Josh,

You can create 2 SUM() expressions with this 2-conditions, then add them.

If you are going to put that in 1 SUM() expression, you will also get the combination for

(FieldA = value1 AND FieldB = value4) and (FieldA = value3 AND FieldB = value2).


so try this...

=SUM({$<FieldA = {value1}, FieldB = {value2}>} fieldname) +

  SUM({$<FieldA = {value3}, FieldB = {value4}>} fieldname)


regards,

Allan

jaimeaguilar
Partner - Specialist II
Partner - Specialist II

Hi,

you can add both expressions within a single set analysis, like this:

=Sum({$<FieldA = {'Value1'}, FieldB={'Value2'}>+<FieldA={'Value3'}, FieldB={'Value4'}>} FieldName)

so you will get:

  1. Coincidences of value1 in FieldA AND value2 in FieldB
  2. Plus coincidences of Value3 in FieldA AND value4 in fieldB

in other words you will get either 1 OR 2

Regards

Anonymous
Not applicable

Thanks Jaime,

jduenyas
Specialist
Specialist
Author

Excelent!

Thanks you so much. That did the trick