Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
yanivvl0
Creator III
Creator III

How to compute Weighted average in a comlicate aggr expresion ?

hi to all ,

in my previos discussion , see  https://community.qlik.com/thread/232790?sr=inbox

i got a great answer from Sunny , look like that :

=Sum({<Key = {"=Aggr(Max(TOTAL <Id> Step), Id, Step) = 4 or Aggr(Max(TOTAL <Id> Step), Id, Step) > Step"}>}Value)


BUT we have another complexity , because the Value is a Weighted average  :

sum ( Id_value * Step_value ) / sum ( Id_value ) .

if we use the Weighted average as Value get a wrong result ,

need your Devoted help.  thanks.

1 Solution

Accepted Solutions
Gysbert_Wassenaar

If you're nesting aggregation functions, which in this case you want to, you need to use the aggr function.

Sum( {<...stuff...>} aggr( sum ( Id_value * Step_value ) / sum ( Id_value ), DimA, DimB, ... DimN) ). Replace DimA, DimB, ... DimN with the dimensions over which the average is weighted.


talk is cheap, supply exceeds demand

View solution in original post

5 Replies
sunny_talwar

What is the dimension on which the weighting is done?

Gysbert_Wassenaar

If you're nesting aggregation functions, which in this case you want to, you need to use the aggr function.

Sum( {<...stuff...>} aggr( sum ( Id_value * Step_value ) / sum ( Id_value ), DimA, DimB, ... DimN) ). Replace DimA, DimB, ... DimN with the dimensions over which the average is weighted.


talk is cheap, supply exceeds demand
sunny_talwar

May be something along these lines

=Sum({<Key = {"=Aggr(Max(TOTAL <Id> Step), Id, Step) = 4 or Aggr(Max(TOTAL <Id> Step), Id, Step) > Step"}>} Aggr(Sum(Id_value * Step_value)/Sum(Id_value), <Dimensions>))

yanivvl0
Creator III
Creator III
Author

hi gysbert  , the dimension is step - and its work fine - Big help , thanks !!

yanivvl0
Creator III
Creator III
Author

its Step - again many thanks Sunny !!