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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

creating aggregation in total table

Hi,

I have to create a total table started from another one which is more detailed, so I'm talking about an aggregation.
My actual table is highlighted in violet in the attachment.
It displays the quantity and the Previous Year Price for each material. Now I have to create the same indicators but at a higher level namely Material_Group.
Being an average, the calculation is made in this way:
First, I have to multiply the quantity by the PY price for each material, then I'll summarize the results and finally I'll divide it by the total quantity. Is in fact the weighted average:
sum(Qty*PY Price)/sum(Qty).
Considering in my table I won't have the detail for material, I think it will be necessary to use some aggregations.
I've tried to do something like this:
(sum(aggr(PY_Price, MAT_MATERIAL_CODE))*
sum(aggr(QUANTITY,MAT_MATERIAL_CODE)))/
sum(QUANTITY)
but I've got an wrong numerator.
Do you have any ideas?

Thank you

1 Solution

Accepted Solutions
Not applicable
Author


The correct formula is

(aggr($(vPYAVGMAT)*sum(TOTAL_QUANTITY), MAT_MATERIAL_CODE, MONTH_MONTH_OF_YEAR))

View solution in original post

5 Replies
hic
Former Employee
Former Employee

You should probably use

     Sum(PY_Price*QUANTITY)/Sum(QUANTITY)

and use MAT_MATERIAL_CODE as dimension.

HIC

Not applicable
Author

Hi,

I tried but I didn't get any correct results. I'm focusing on getting the numerator value (PY*QTY)

I've attached my application. In the MATERIAL LEVEL block I have all the materials, on the row PY AVG MAT*QTY I calculated the product between PY and QTY.

Now I should do the same in the GROUP LEVEL block, on the row avg*QTY, but I don't get any result.

For example, for January I'm expecting to get the sum of  PY AVG MAT*QTY for all materials. It would be 157126.346.

Not applicable
Author


I did it. It was missing the aggregation for month.

Not applicable
Author


I wa wrong. It works only for the january e february. For march I got wrong numbers. I don't understand why. It's very strange.

Please, see in the attachment the formula I used.

Not applicable
Author


The correct formula is

(aggr($(vPYAVGMAT)*sum(TOTAL_QUANTITY), MAT_MATERIAL_CODE, MONTH_MONTH_OF_YEAR))