Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Expression for weighted average?

Hi - I need to calculate the sum of three Departments' downtime based on metrics per Line. I need to calculate it as a weighted average as each Department has a different number of Lines.

Can anyone tell me what is wrong with my syntax?

=Sum({<Department = {('Dept1'/6), ('Dept2'/3), ('Dept3'/9)}>}Percentage))

Thank you!

1 Solution

Accepted Solutions
oknotsen
Master III
Master III

Put them all in 1 line and put a + symbol between them.

Just a best guess of course, as I don't know your data model and also am not 100% sure about what you are aiming at.

May you live in interesting times!

View solution in original post

7 Replies
oknotsen
Master III
Master III

You are trying to divide dimension values by 6, 3 and 9, not the sum of the measures related to those values.

Split that thing into 3 (sub-) expressions (one for each dept) and divide the result of each expression to the right weight. Add those together.

May you live in interesting times!
swuehl
MVP
MVP

That's hard to tell without knowing something about your model, fields, data values.

What are ('Dept1'/6), ('Dept2'/3), ('Dept3'/9)? Field values in Department?

Maybe try something like

=Sum({<Department = {'Dept1','Dept2','Dept3'} >}  Downtime)

/ Count({<Department = {'Dept1','Dept2','Dept3'} >} Downtime)

Not applicable
Author

Could you show me please? I'm not getting the syntax right.

So this is basically what I need:

Sum({<Department = {'Dept1'}>}Percentage) /6
Sum({<Department = {'Dept2'}>}Percentage) /3
Sum({<Department = {'Dept3'}>}Percentage) /9

How do I add them together? Sorry - I'm learning!

Not applicable
Author

"Department" = 'Dept1', 'Dept2', and 'Dept3'

"Percentage" is the metric I need to sum for all three departments.

Dept1 has 6 Lines, Dept2 has 3 Lines, and Dept3 has 9 Lines. I need to sum "Percentage" as a weighted average, because each department has a different number of Lines.

oknotsen
Master III
Master III

Put them all in 1 line and put a + symbol between them.

Just a best guess of course, as I don't know your data model and also am not 100% sure about what you are aiming at.

May you live in interesting times!
Not applicable
Author

Thank you!

oknotsen
Master III
Master III

Happy I could help .

May you live in interesting times!