Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
jood_ahmad
Creator II
Creator II

calculation using nested sum

Dears,

Can you advice on this calculation , what is wrong

=Sum(sum(

  Sum(ACT_QTY_CLOSE) * Sum(UNIT_EQUIVALENCE))

+

  Sum((Sum(ACT_QTY_OPEN) *Sum(UNIT_EQUIVALENCE)) + (sum(ITEM_QUANTITY_PUR * ITEM_PURCHASE_EQUIVALENCE) * Sum(UNIT_EQUIVALENCE)))

-

  Sum((sum(ITEM_CONSUMPTION)* Sum(UNIT_EQUIVALENCE)) + Sum(WASTAGES))

* ITEM_PURCHASE_PRICE)

any help please.

ecolomerrubenmarin

Message was edited by: Ahmad Kastero

19 Replies
marcus_sommer

It's not possible to nest aggregations without an AGGR...

- Marcus

jood_ahmad
Creator II
Creator II
Author

Hi Marcus,

i try to do it wit Aggr but it is not work ,

i try with the main field that i need to do the calculation on it (%Cons_Item_Key) .

is there is another way or only we can do it by using AGGR.

rubenmarin

Hi Ahmad, maybe using RangeSum:

RangeSum(

RangeSum(Sum(ACT_QTY_CLOSE) * Sum(UNIT_EQUIVALENCE))),

RangeSum(Sum(ACT_QTY_OPEN) *Sum(UNIT_EQUIVALENCE),

                   sum(ITEM_QUANTITY_PUR * ITEM_PURCHASE_EQUIVALENCE) * Sum(UNIT_EQUIVALENCE))

-RangeSum(sum(ITEM_CONSUMPTION)* Sum(UNIT_EQUIVALENCE),

                    Sum(WASTAGES))

) * ITEM_PURCHASE_PRICE)


Not tested, maybe there is a typo... and I never used RangeSum this way, so I'm not sure if this can work.

                  

jood_ahmad
Creator II
Creator II
Author

Thank you Ruben, but unfortunately not working .

marcus_sommer

If you could logically replace the sum() around the sum(Fields) with a + than you could go with the approach from Ruben otherwise you will need the aggr() with the proper dimensions to those parts where you couldn't replace them.

- Marcus

marcus_sommer

Do it step by step and give each part a single expression and if they work like expected put them together and check again.

- Marcus

rubenmarin

I did it more simpler and worked but, as I said, I'm not sure if that complexity can work (I don't see why not).

And also it was written directly in the post, so typo's may appear, rigth now I saw a lack of a comma:

Sum(UNIT_EQUIVALENCE)), //This comma was forgotten in my previous post

jood_ahmad
Creator II
Creator II
Author

Dears,

i add a sample for my target bar chart and my reference value in table ( Recipe Consumption) if you see in this table the last column is the VALUED DIFFERENCE this column result of all that nested sum but when i try to do it in bar chart i can't.

i need to see for each item the total of VALUED DIFFERENCE in bar chart even (Positive or Negative value). this is my target.

rubenmarin

Hi Ahmad, the expression 'Theo.Cons.Recipe Qty' is a conditional expression, when the condition is false the expression is not calculated, so every other expression that uses this expression can't be calculated.

You can transform the null in 0 using Alt(): Alt([Theo.Cons.Recipe Qty],0), but the deference% will also return null (it will be a division by zero).

If what you want is to hide this column but still use the values use the conditional show in the presentation tab instead of the conditional expression of the expression tab.

And the VALUE difference column can't be calculated that way because it has many different values for ITEM_PURCHASE_PRICE, it should be only one value (using an expressiont hat returns that value) or using aggr() so it uses different ITEM_PURCHASE_PRICE for each Aggr() dimension value... but I think this wouldn't be fit the intention of the expression so you need to kwon what to do with all the different ITEM_PURCHASE_PRICE... wich value has to be used in VALUE DIFFERENCE?