cancel
Showing results for 
Search instead for 
Did you mean: 

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

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors