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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
user467341
Creator II
Creator II

Calculating weighted average with categorical

Hi all. I have a sample table below

Cat Hrs
AA 4
FF 6
BB 14
FF 64
FF 13
CC 52
AA 52
DD 46
ZZ 87

I am trying to calculate the weighted average of the same category but I am not sure how to do this.

What I have thought of was

SUM(hrs * COUNT(cat)) / COUNT(cat)

However I am not sure how to approach the bold part to get the count of each cat.

My goal is to use this set expression in a bar chart to display the data.

Any help is greatly appreciated, thank you.

Labels (1)
3 Replies
vinieme12
Champion III
Champion III

Weighted average will always have at least 2 measures, in your case you could just do Avg(Hrs) since you don't have a second measure

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
sk88024
Creator
Creator

this might work - 

Sum(Aggr(Avg(Hrs), Cat))

Aditya_Chitale
Specialist
Specialist

Try this:

sum(Hrs * Aggr(nodistinct Count(Cat),Cat))/count(total Cat)

Aditya_Chitale_0-1680072361263.png

 

Regards,

Aditya