Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello, I'm not sure how to count separate values in the same row.
I have a survey that scores an employee's service. The problem is a survey can contain multiple employees and scores. I would like to count how many times an employee has a survey and then get their corresponding score for a report. Thank you.
Employees Table:
EmployeeID | EmployeeName |
001 | John |
002 | Matt |
003 | Jessica |
004 | Ronald |
005 | Valerie |
Survey Table:
Survey# | Employee1 | Score1 | Employee2 | Score2 | Employee3 | Score3 |
001 | John | 5 | ||||
002 | John | 5 | ||||
003 | Matt | 5 | Jessica | 5 | Ronald | 5 |
004 | Ronald | 5 | Matt | 5 | ||
005 | John | 5 | Jessica | 5 |
The result should be:
EmployeeName | SurveyCount | SurveyScore |
John | 3 | 15 |
Matt | 2 | 10 |
Jessica | 1 | 5 |
Ronald | 2 | 10 |
Valerie |
Solved! Go to Solution.
*******************As suggested by some AI tools***************************
To achieve the desired result using Power Query or DAX, you'll need to transform your Survey Table to a more normalized format, where each survey entry for an employee is on a separate row. This will make it easier to count surveys and sum scores per employee. Here's how you can do it:
*******************As suggested by some AI tools***************************
To achieve the desired result using Power Query or DAX, you'll need to transform your Survey Table to a more normalized format, where each survey entry for an employee is on a separate row. This will make it easier to count surveys and sum scores per employee. Here's how you can do it:
- Filter out rows where Attribute does not end with the number that corresponds to your EmployeeName's unpivoted position (e.g., if EmployeeName came from Employee1, keep only rows where Attribute is Score1).
Sorry for the late reply. How would I filter Employee1 and only keep Score1, Employee2 and only keep Score2, and Employee3 and only keep Score3?
- Use the "Unpivot Columns" feature to convert the Employee and Score columns into rows. You'll need to unpivot twice: once for the Employee columns and once for the Score columns.
Thank you, that did it!
To solve this, you can unpivot the Survey Table in Power Query to make it more manageable for analysis and then use measures or calculated columns in Power BI to compute the desired results.
Unpivot the Survey Table:
Clean the Data:
Merge with the Employee Table:
Load Data to Power BI.
Create the SurveyCount Measure:
This counts the number of rows for each employee, representing the surveys they participated in.
Create the SurveyScore Measure:
This sums up the scores for each employee.
Build the Report Table:
John | 3 | 15 |
Matt | 2 | 10 |
Jessica | 1 | 5 |
Ronald | 2 | 10 |
Valerie | 0 | 0 |
This approach ensures you capture the survey count and corresponding scores correctly for each employee.
Thank you for your reply. I have a bit of an inssue on this step:
When I unpivot the table it looks like this:
Survey# | Attribute | Value |
001 | Employee1 | John |
001 | Score1 | 5 |
002 | Employee1 | John |
002 | Score1 | 5 |
003 | Employee1 | Matt |
003 | Score1 | 5 |
003 | Employee2 | Jessica |
003 | Score2 | 5 |
003 | Employee3 | Ronald |
003 | Score3 | 5 |
004 | Employee1 | Ronald |
004 | Score1 | 5 |
004 | Employee2 | Matt |
004 | Score2 | 5 |
005 | Employee1 | John |
005 | Score1 | 5 |
005 | Employee2 | Jessica |
005 | Score2 | 5 |
Not sure how to continue from here