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
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:

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:

 

FormIdStudents.IdSubjectGrade
11EnglishB
22EnglishB
33EnglishD
41MathsA
52MathsD
63MathsB

 

SubjectAverageEnglishAverageMaths
English75% 
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

@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.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@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.

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:

 

Grades

FormIdStudents.IdSubjectGrade
11EnglishB
22EnglishB
33EnglishD
41MathsA
52MathsD
63MathsB
71FrenchA
82FrenchC
93FrenchB
101LatinB
112LatinA
123LatinF
131BiologyB
142BiologyB
153BiologyA

 

Percentages

Mapping.IdGradePercentage
Map1A100
Map2B85
Map3C75
Map4D65
Map5F50

 

GradeAverage (desired outcome):

English78,33%
French86,67%
Latin78,33%
Maths83,33%
Biology90%

 

Actual wrong result:

SubjectAverage
English75%
French86,67%
Latin78,33%
Maths83,33%
Biology92,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.

Anonymous
Not applicable

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

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.

Top Solution Authors