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

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

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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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