Forum Discussion
Weighed Average for User Feedback
Dear all,
I have read some articles here in regards of the weighed average DAX expression. But I was not able to get the needed solution (or I am just not skilled enough).
My current situtaion is, that I have table (example below).
I have overall 5 questions and the needed WAC needs to be filtered for each supplier.
| Supplier ID | Date | Supplier | Question1 | Question2 | Question3 | Question4 | Question5 |
| 1 | 01.08.2020 | a | 4 | 2 | 2 | 3 | 4 |
| 2 | 01.08.2020 | b | 2 | 3 | 4 | 4 | 2 |
| 3 | 01.08.2020 | c | 3 | 3 | 2 | 2 | 1 |
| 1 | 20.08.2020 | a | 2 | 3 | 4 | 4 | 5 |
| 2 | 20.08.2020 | b | 1 | 2 | 4 | 5 | 3 |
I need to calculate the weighed average for the supplier for each question with this formula:
WAC = (Amount of people who selected 1 * 1) + (Amount of people who selected 2 * 2) + (Amount of people who selected 3 * 3) + (Amount of people who selected 4 * 4) + (Amount of people who selected 5 * 5) / Total Amount of people
--> Example WAC for supplier A for Question 1 = (0*1)+(1*2)+(0*3)+(1*4)+(0*5) / 8 --> 0+2+0+4+0 / 2 --> 6 / 2 = 3
I hope I could give you the needed information to help me 🙂
Thanks and cheers,
Kai
Hi Kaitra ,
First try to unpivot your table:
Then create a calculated column for weighted:
weighted = VAR a = CALCULATE ( COUNT ( 'Table'[Supplier] ), ALLEXCEPT ( 'Table', 'Table'[Question], 'Table'[Supplier] ) ) VAR b = CALCULATE ( COUNT ( 'Table'[Supplier] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Question], 'Table'[Supplier] ), 'Table'[Value] = EARLIER ( 'Table'[Value] ) ) ) RETURN b / aLast create the measure for WAC:
WAC = SUMX(SUMMARIZE('Table','Table'[Supplier],'Table'[Question],'Table'[Value],'Table'[weighted],"weightedvalue",'Table'[Value]*'Table'[weighted]),[weightedvalue])For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/Ec9jvEYkrDBGh-4Ghsieaa4BELptGFAnzBcf7rayyZLQ5A?e=KW2PHI
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
2 Replies
- amitchandak
Super User
Kaitra , I think you should unpivot this data
https://radacad.com/pivot-and-unpivot-with-power-bi
Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/Then you can have logic to multiple in a column based on rating
- v-deddai1-msft
Community Support
Hi Kaitra ,
First try to unpivot your table:
Then create a calculated column for weighted:
weighted = VAR a = CALCULATE ( COUNT ( 'Table'[Supplier] ), ALLEXCEPT ( 'Table', 'Table'[Question], 'Table'[Supplier] ) ) VAR b = CALCULATE ( COUNT ( 'Table'[Supplier] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Question], 'Table'[Supplier] ), 'Table'[Value] = EARLIER ( 'Table'[Value] ) ) ) RETURN b / aLast create the measure for WAC:
WAC = SUMX(SUMMARIZE('Table','Table'[Supplier],'Table'[Question],'Table'[Value],'Table'[weighted],"weightedvalue",'Table'[Value]*'Table'[weighted]),[weightedvalue])For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/Ec9jvEYkrDBGh-4Ghsieaa4BELptGFAnzBcf7rayyZLQ5A?e=KW2PHI
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai