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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Weighted average calculation

Hello,

I need a little help calculating weighted average in QlikView.

In database table, with customer orders, i have column for quantity and column for price per unit. I need to calculate weighted average price for customer in expression on bar chart:

(Price * Quantity)/ total Quantity = weighted average price for customer orders

I tried few things, but I couldn't calculate it correctly.

Thanks in advance.

Bojan

1 Solution

Accepted Solutions
sunny_talwar

May be this in a straight table

Dimension:

CustomerOrder

Expression:

Sum(Price * Quantity)/Sum(Quantity)

or this in a text box object

Sum(Aggr(Sum(Price * Quantity)/Sum(Quantity), CustomerOrder))

View solution in original post

5 Replies
sunny_talwar

May be this in a straight table

Dimension:

CustomerOrder

Expression:

Sum(Price * Quantity)/Sum(Quantity)

or this in a text box object

Sum(Aggr(Sum(Price * Quantity)/Sum(Quantity), CustomerOrder))

Anonymous
Not applicable
Author

This with expression helped, thank you very much, I wasn't thinking in that direction.

Regards

Anonymous
Not applicable
Author

And how would you apply this solution (e.g. Sum(Price * Quantity)/Sum(Quantity))  in a set analysis?

namely where you defined Price as  sum( {<measure={'Price}>} Value) and Quantity as sum( {<measure={'Quantity'}>} Value)

sunny_talwar

I guess something like this

Sum(Aggr(Sum({<measure={'Price}>} Value)*Sum({<measure={'Quantity'}>} Value), Item))/Sum({<measure={'Quantity'}>} Value)

veronicahernand
Partner - Contributor III
Partner - Contributor III

This is wonderful!!!! thankssssssssss!!!!!!!!!!!!!