Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hgmc
Frequent Visitor

Calculating Weighted Average of (Text) Survey Answers

Hello,

 

Short of making dozens and dozens of small formulas is there an effective way to calculate a weighted average for each question in survey data. I want to use these weighted average answers as sources for various graphs in Power Bi.

 

Sample Data:

It is a survey format so there may be multiple responses for a particular candidate, in this case BOB had 3, JANE had 2. (I'll be using a slicer to filter by candidate name)

 

Answers are text format and I need to assign them weighting in the formula, For exmaple, Excellent = 3 points, Average = 2 points, Poor = 1 point

 

I need to calculate the weighted average for each candidate, for each question.

 

Spent so much time trying different formulas and browsing on this forum but can't seem to find a similar situation. Any help is much appreciated! (ChatGPT actually got me halfway there!)

 

Candidate Name  Question 1  Question 2  Question 3 

BOB

ExcellentAverageAverage
BOBAveragePoorPoor
BOBPoorExcellentExcellent
JANEExcellentExcellentPoor
JANEAverageAverageExcellent

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @hgmc 

the point is to unpivot your data and add a custom column into a table like this:

 

CandidateName Question Answer Point

BOB Question1 Excellent 1

BOB Question2 Average 2

BOB Question3 Average 2

...

 

then everything becomes intuitive with DAX. 

 

About unpivot:

https://learn.microsoft.com/en-us/power-query/unpivot-column

 

 

 

View solution in original post

3 REPLIES 3
rautaniket0077
Resolver I
Resolver I

1) use conditional formatting for assigning values to the questions.

rautaniket0077_0-1679736473098.png

2) use the below measure.

Measure =
var a =        
 SWITCH(
            TRUE(),
            MIN(Sheet1[ Question 1 ]) = "Excellent", 3,
            MIN(Sheet1[ Question 1 ]) = "Average",2,
            MIN(Sheet1[ Question 1 ]) = "Poor",1
       
)  

Var b = CALCULATE(
            SUM(Sheet1[Question 1 No]),
            ALLSELECTED(Sheet1)
)

return (a/b) * a

3) you will get your desired output
rautaniket0077_1-1679736624105.png

4) similarly you can do it for question 2 and 3

if this solves your issue please accept my answer as solution.



FreemanZ
Super User
Super User

hi @hgmc 

the point is to unpivot your data and add a custom column into a table like this:

 

CandidateName Question Answer Point

BOB Question1 Excellent 1

BOB Question2 Average 2

BOB Question3 Average 2

...

 

then everything becomes intuitive with DAX. 

 

About unpivot:

https://learn.microsoft.com/en-us/power-query/unpivot-column

 

 

 

hgmc
Frequent Visitor

Thank-you, looked a bit daunting at first to unpivot as I didnt really understand what I was doing but it did work in the end!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.