cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Anonymous
Not applicable

DAX: Why are duplicate values excluded when calculating an average?

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:

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?

1 ACCEPTED SOLUTION
Super User

@Anonymous , Please find the attached file after signature.

Two solutions, using new column (then avg) and new measure

Tutorial Series Dax Vs SQL Direct Query PBI Tips

4 REPLIES 4
Super User

@Anonymous , the formula is correct , may be you need

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Tutorial Series Dax Vs SQL Direct Query PBI Tips

Anonymous
Not applicable

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:

 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

 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%
Super User

@Anonymous , Please find the attached file after signature.

Two solutions, using new column (then avg) and new measure

Tutorial Series Dax Vs SQL Direct Query PBI Tips

Anonymous
Not applicable

Thank you so much, that is exactly what I was looking for!