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

Weighted Average

Hello,

does someone would know how to calculate an average in a total according to others records?

Let say columns A is a sum(quantity), column B is already an average result of the quantity  (price)

Qty     Price

100        2 €

150        3 €

200       2,5€

------------------

450      avg(price) sould be   ((100 * 2) + (150 * 3) + (200 * 2.5) ) / 450

How can I get this?

best regards

Chris

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Christian

You are almost there. I think you need this:

Sum(Aggr(Sum(Q * P, Dim), Dim)) / Sum(TOTAL Q)

Regards

Jonathan

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

View solution in original post

6 Replies
nirav_bhimani
Partner - Specialist
Partner - Specialist

HI,

You want to do Avg of sum then try the following exp.

Avg ( Sum (Quantity* Price) ) / sum(Qunatity)

Regards,

Nirav Bhimani.

Not applicable
Author

Sorry, but you can't write this expression

I tried with an avg(aggr (sum(Q*P, Dim) / sum(Q)

but it doesn't give a good result either

christian

jonathandienst
Partner - Champion III
Partner - Champion III

Christian

You are almost there. I think you need this:

Sum(Aggr(Sum(Q * P, Dim), Dim)) / Sum(TOTAL Q)

Regards

Jonathan

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

Thank you John,

it matches with the result I got whan I compute in the script.

best regards

christian

hic
Former Employee
Former Employee

Jonathans formula calculates the correct answer, but... it is unnecessarily complicated. The Aggr() function is not needed. Just do

Sum(Price*Qty)/Sum(Qty)

HIC

jonathandienst
Partner - Champion III
Partner - Champion III

Well spotted Henric! 

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