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: 
thanhphongle
Creator II
Creator II

Calculating the weighted average of terms

Hello community,

this is my database

Order IDProductWaiting time in months
1iPhone 636
2iPhone 6+48
3Samsung Galaxy S672
4Samsung Note 424
5iPhone 760
6iPhone 7+24

I want to calculate the weighted average of the waiting time in a barchart.

My first appendage was.

I didnt pick any dimension as I want to the weighted avg of all waiting time. My expression is.

sum((sum([Waiting time in months]/sum(TOTAL [Waiting time in months]))*[Waiting time in months])

This is not really working because I was using a multiple functions.

So I tried in the second step to add the Order ID as dimension and used the following expession.

sum([Waiting time in months]/sum(TOTAL [Waiting time in months]))*[Waiting time in months]

The result is, that qv  returns me the percentage of the weighted avg waiting time for each order ID.

But I need the sum of all calculated avg weights.

The result shoud be 51.27 !

Could anyone help me out here?

1 Solution

Accepted Solutions
tresesco
MVP
MVP

PFA (Used the same expression suggested above)

Capture.PNG

Edit: In fact 'Total' before aggr() would not be required without a dimension.

View solution in original post

7 Replies
tresesco
MVP
MVP

Do you wish to see same avg value 51.27 across all Order IDs?

tresesco
MVP
MVP

If so try:

Sum(total Aggr(Sum([Waiting time in months])/Sum(TOTAL [Waiting time in months])*[Waiting time in months], [Order ID]))

sunny_talwar

How are you even coming up with 51.27 here? Can you explain the calculation here?

thanhphongle
Creator II
Creator II
Author

No I just want to have one bar and actually I dont want to pick any Dimension for this.

You can see my calculation in the attached Excel File.

tresesco
MVP
MVP

PFA (Used the same expression suggested above)

Capture.PNG

Edit: In fact 'Total' before aggr() would not be required without a dimension.

sunny_talwar

How about just this:

Sum(Aggr(([Waiting time in months]/Sum(TOTAL [Waiting time in months]))*[Waiting time in months]), [Order ID]))


Sum(Aggr(([Waiting time in months]/Sum(TOTAL [Waiting time in months])*[Waiting time in months]), [Order ID]))

UPDATE: Misplaced some parenthesis

thanhphongle
Creator II
Creator II
Author

Thank you for your help guys !!!