Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Karl_Hart
Creator
Creator

Sum Aggr Sum with multiple set analysis query

Hi all,

I have an expression where I need to use multiple set analysis criteria. A simplified version is below

Sum({<Set Analysis Criteria 1>} Aggr (Sum {<Set Analysis Criteria 1>}  Sales), Division))

+

Sum({<Set Analysis Criteria 2>} Aggr (Sum {<Set Analysis Criteria 2>}  Sales), Division))


I was hoping and expecting that I could combine them into a simpler version, e.g.

Sum({<Set Analysis Criteria 1>+<Set Analysis Criteria 2>}

Aggr (

Sum {<Set Analysis Criteria 1>+<Set Analysis Criteria 2>}  Sales), Division))


but this isnt giving me the same answer.


Does it not work like this? Or is it not working in mine becuse of the set analysis criteria I am using?


I would be grateful of any help.


Also, as a side question, do I necessary need the same Set analysis criteria after both "sums" in a sum-aggr-sum expression?

1 Solution

Accepted Solutions
sunny_talwar

Another way to do this would be (not that it would be any better)

Sum(Aggr(

     RangeSum(Sum({<Transaction_Type={'C'}>}Value),

     -Sum({<Transaction_Type={'C'}, Customer_Name={'Void'}>}Value),

     -Sum({<Transaction_Type={'C'}, Customer_Type={2}, Customer_Name={'*'}-{'Void'}>}Value))

, CustomerID, Week))

View solution in original post

8 Replies
sunny_talwar

Not always are they going to work... if the set analysis overlap, the sum from the two expressions can overlap and the two expressions can give you very different numbers.

For your second question, it usually makes sense to add the same set analysis from your inner aggregation to your outer aggregation

Anil_Babu_Samineni

Please post full metric to check

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Karl_Hart
Creator
Creator
Author

My real expression is something more like

Sum ({<Transaction_Type={'C'}>}

Aggr (Sum {<Transaction_Type={'C'}>}Value), CustomerID, Week))

-

Sum ({<Transaction_Type={'C'},  Customer_Name={'Void'}>}

Aggr (Sum {<Transaction_Type={'C'}, Customer_Name={'Void'}>}Value), CustomerID, Week))

-

Sum ({<Transaction_Type={'C'}, Customer_Type={2}, Customer_Name={'*'}-{'Void'}>}

Aggr (Sum {<Transaction_Type={'C'}, Customer_Type={2}, Customer_Name={'*'}-{'Void'}>}Value), CustomerID, Week))

So, its a case of

Show me the sum off all C transactions

Less all C transactions for Voids

Less all C transactions for Type 2 customers except Voids (as they have been excluded above)

If someone can show me a better / cleaner way of writing that, I would appreciate it

sunny_talwar

Another way to do this would be (not that it would be any better)

Sum(Aggr(

     RangeSum(Sum({<Transaction_Type={'C'}>}Value),

     -Sum({<Transaction_Type={'C'}, Customer_Name={'Void'}>}Value),

     -Sum({<Transaction_Type={'C'}, Customer_Type={2}, Customer_Name={'*'}-{'Void'}>}Value))

, CustomerID, Week))

pradosh_thakur
Master II
Master II

in which object you are using the expression ? as you are using aggr(sum() it must be a text box.

Karl Hart wrote:

So, its a case of

Show me the sum off all C transactions

Less all C transactions for Voids

Less all C transactions for Type 2 customers except Voids (as they have been excluded above)

If someone can show me a better / cleaner way of writing that, I would appreciate it

when you said less all you meant diffrence or exclusion ? if exclusion and i understood it correctly than you dont need a complex expression.

Learning never stops.
sasikanth
Master
Master

HI,

try this

Sum(

     Aggr(

                 Sum ( {<Transaction_Type={'C'} ,  Customer_Type-={2} , Customer_Name-={'Void'}>} Value)

            , CustomerID, Week

             )

        )

Karl_Hart
Creator
Creator
Author

Thanks, that has worked and reduced the calculation time - which is what I was trying to achieve with this

Karl_Hart
Creator
Creator
Author

Thank you, I did think about this after I posted the question, but there is another criteria which I didnt include which means there is some overlapping and so this wouldnt work in my case