Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set analysis 'AND' & 'OR' in same expression

Hi,

Hoping someone can help.

Effectively I want to use a combination of logic in a single set analysis fomula. I understand that a comma is used in set analysis to get a result where both conditions are true (AND), and that a + is used for when either condition is true. Effectively, I want the amount to be summed when one condition (that yearvalue is current year) is always true, but when a condition is in a range of other values. Sample below.

=(SUM({$<dim_YearValue={$(=YEAR(TODAY()))}>,

<CustomerBusinessArea={'ba1'}>

+ <customerBusinessArea={'ba2'}>

+ <customerBusinessArea={'ba3'}>

+ <customerBusinessArea={'ba4'}>

+ <customerBusinessArea={'ba5'}>

+ <customerBusinessArea={'ba6'}>

+ <customerBusinessArea={'ba7'}>} AMOUNT))

Thanks in advance

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

All you need is:

SUM({$<dim_YearValue = {$(=YEAR(TODAY()))},

CustomerBusinessArea={'ba1', 'ba2', 'ba3', 'ba4', 'ba5', 'ba6', 'ba7'}>} AMOUNT)

This will AND the two conditions (dim_YearValue  and CustomerBusinessArea) . The CustomerBusinessArea condition will return true for any of the values in the list (OR)

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

5 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

All you need is:

SUM({$<dim_YearValue = {$(=YEAR(TODAY()))},

CustomerBusinessArea={'ba1', 'ba2', 'ba3', 'ba4', 'ba5', 'ba6', 'ba7'}>} AMOUNT)

This will AND the two conditions (dim_YearValue  and CustomerBusinessArea) . The CustomerBusinessArea condition will return true for any of the values in the list (OR)

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable
Author

I guess you need this:

sum(

{$<dim_YearValue={"$(=YEAR(TODAY()))"}, CustomerBusinessArea={'ba1','ba2','ba3','ba4','ba5','ba6','ba7'}>}

AMOUNT)

rubenmarin

Hi Dave, maybe intersection is what you're searching:

=(SUM({$<dim_YearValue={$(=YEAR(TODAY()))}>,

<CustomerBusinessArea*={'ba1','ba2','ba3'.....}>} AMOUNT))

After the *= QV will detect an error but on top of expression it says 'Expression OK', so it should work.

PrashantSangle

Hi,

Try below

=(SUM({$<dim_YearValue={"$(=YEAR(TODAY()))"},

CustomerBusinessArea={'ba1','ba2','ba3','ba4','ba5','ba6','ba7'}>} AMOUNT))

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Not applicable
Author

Thanks to everyone, Jonathan got there first.