Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I have the following situation: I have a table that assigns a school grade to each student per subject. Then I have a second mapping table that assigns a percentage value (100%, 85%, 75%, 65%, 50%) to each school grade (A, B, C, D, F).
Now I want to calculate the average grade in percent for each school subject. I have already found the following solution:
AverageEnglish = Calculate(average(Percentages[Percentage]),Filter(Grades, (Grades[Subject])="English"))
However, this solution is not correct because I am looking for a measure that calculates the average for each school subject and not just for one specific subject (in this case English). Also, the result is wrong because if two students have the same grade in a subject, the double values are left out of the calculation. See this example where two students have the grade "B" in English:
FormId | Students.Id | Subject | Grade |
1 | 1 | English | B |
2 | 2 | English | B |
3 | 3 | English | D |
4 | 1 | Maths | A |
5 | 2 | Maths | D |
6 | 3 | Maths | B |
Subject | AverageEnglish | AverageMaths |
English | 75% | |
Maths | 83,33% |
As you can see above, the result is therefore correct for mathematics but wrong for English. Does anyone have an idea how to solve this problem?
Solved! Go to Solution.
@Anonymous , Please find the attached file after signature.
Two solutions, using new column (then avg) and new measure
Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.
@Anonymous , the formula is correct , may be you need
AverageEnglish = Calculate(averagex(values(Table[School]), calculate(Percentages[Percentage])),Filter(Grades, (Grades[Subject])="English"))
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.
Hello!
I tried your measure but unfortunately it gives the same error, so the double values are left out.
I do not know how to share files on this board. But here are my sample tables:
Grades
FormId | Students.Id | Subject | Grade |
1 | 1 | English | B |
2 | 2 | English | B |
3 | 3 | English | D |
4 | 1 | Maths | A |
5 | 2 | Maths | D |
6 | 3 | Maths | B |
7 | 1 | French | A |
8 | 2 | French | C |
9 | 3 | French | B |
10 | 1 | Latin | B |
11 | 2 | Latin | A |
12 | 3 | Latin | F |
13 | 1 | Biology | B |
14 | 2 | Biology | B |
15 | 3 | Biology | A |
Percentages
Mapping.Id | Grade | Percentage |
Map1 | A | 100 |
Map2 | B | 85 |
Map3 | C | 75 |
Map4 | D | 65 |
Map5 | F | 50 |
GradeAverage (desired outcome):
English | 78,33% |
French | 86,67% |
Latin | 78,33% |
Maths | 83,33% |
Biology | 90% |
Actual wrong result:
Subject | Average |
English | 75% |
French | 86,67% |
Latin | 78,33% |
Maths | 83,33% |
Biology | 92,50% |
@Anonymous , Please find the attached file after signature.
Two solutions, using new column (then avg) and new measure
Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.
Thank you so much, that is exactly what I was looking for!
User | Count |
---|---|
14 | |
9 | |
7 | |
7 | |
6 |
User | Count |
---|---|
22 | |
11 | |
10 | |
10 | |
8 |