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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
pconridge
Frequent Visitor

Calculating how a students grade in a subject compares to their average grade.

Hi,

I have pasted at the bottom of this post a table of student assessment results.

I would be very grateful for help to create a DAX measure that calculates how a student's grade in a particular subject (aspect) compares to that students average grade in the other subjects they have a result for.

I want teachers to be able to see how a student's performance in their subject is different compared to that students performance in their other subjects.  I'd also like to be able to show an aggregated residual for subjects in a seperate table.

 

For example the table below shows what i am trying to achieve.

This student has an average Year 11 Predicted grade 1 value of 4.36  

This has been subtracted from their grade for each subject to give the residual column.

 

Student IdResultsetGrade valueAspectResidual
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Art WL18-251.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 Design Tech WL 19-250.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 English Lang WL 17-250.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 English Lit WL 17-250.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 French WL18-240.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 Geography WL18-250.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Maths WL 17-251.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Religious Stud WL18-251.64
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Science Trilogy WL18-251.64
  4.36  

 

ChatGpt suggested the following DAX however as the screenshot for one particular student shows this is producing the wrong answer.

Residual =
VAR SelectedStudent = SELECTEDVALUE(AssessmentY11[Student])

VAR AvgGrade =
CALCULATE(
AVERAGE(AssessmentY11[Grade Value]),
ALL(AssessmentY11),
AssessmentY11[Student] = SelectedStudent,
AssessmentY11[Aspect] IN VALUES(AssessmentY11[Aspect]),
AssessmentY11[Result Set] = "Year 11 Predicted 1"
)

RETURN
IF(
NOT ISBLANK(AvgGrade),
AVERAGE(AssessmentY11[Grade Value]) - AvgGrade,
BLANK()
)

pconridge_0-1705320208630.png

 

Any help much appreciated.

Thanks

Phil

I need to restrict the aspects being considered to the following:

AssessmentY11[aspect] IN { "KS4 Art WL18-24","KS4 Art WL18-25""KS4 Biology WL18-25","KS4 BTEC Art and Design WL 24",
"KS4 BTEC Sport WL 24-25","KS4 BTEC Tech DIT WL 24-25","KS4 BTEC Vocational WL 23-25","KS4 BTEC Workskills WL 23-25",
"KS4 Business Studies WL 19-25","KS4 Chemistry WL18-25","KS4 Computer Science WL 20-25","KS4 Design Tech WL 19-25",
"KS4 Drama WL18-25","KS4 Engineering Award WL 24-25","KS4 English Lang WL 17-25","KS4 English Lit WL 17-25","KS4 Food and Nutrition WL 21-25","KS4 French WL18-24","KS4 Geography WL18-25","KS4 History WL18-25","KS4 Hospitality Award WL 20-23",
"KS4 Hospitality Award WL 24-25","KS4 Maths WL 17-25","KS4 Media Studies WL 19-25","KS4 Music WL18-25","KS4 Physics WL18-25","KS4 Religious Stud WL18-25","KS4 Science Trilogy WL18-25","KS4 Spanish WL 18-25","KS4 SPE WL18-25"

 

Here are the results for two pupils

External IdResultsetGrade valueAspect 
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Art WL18-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Religious Stud WL18-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 English Lang WL 17-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 English Lit WL 17-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Maths WL 17-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 Design Tech WL 19-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 16KS4 Science Trilogy WL18-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 11Difference Art PG tp target
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 1-1Difference English Lan PGTG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 11Difference Religious StPGTG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 11Difference FrenchPGTG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 1-1Difference English Lit PGTG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 French WL18-24
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 15KS4 Geography WL18-25
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff DT PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff RS PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff EngLit PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff Geog PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff Maths PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff French PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 12Difference Science Tril PG TG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff Scien Tril PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff Art PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Diff EngLan PG to Expected
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Difference MathsPGTG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 10Difference GeographyPGTG
000c75c0-5dfb-4e8c-a2b0-a50a4dd341c2Year 11 Predicted 11Difference DT Product PG TG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 18KS4 Religious Stud WL18-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 19KS4 Biology WL18-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 19KS4 Chemistry WL18-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 17KS4 English Lang WL 17-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 17KS4 English Lit WL 17-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 18KS4 Maths WL 17-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 11Difference Computer ScPGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Difference English Lan PGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 12Difference Religious StPGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 11Difference PhysicsPGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 12Difference FrenchPGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Difference English Lit PGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 18KS4 French WL18-24
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 17KS4 Music WL18-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 17KS4 Physics WL18-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 17KS4 Computer Science WL 20-25
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 11Difference Music PG TG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff Physics PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff RS PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff French PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff EngLit PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff Maths PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff Music PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff Biology PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff Chemistry PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff Comp Studies PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 10Diff EngLan PG to Expected
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 13Difference ChemistryPGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 11Difference MathsPGTG
00e8c871-07cf-4144-8d56-a77cf84d3d5fYear 11 Predicted 13Difference Biology PG to Target
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 11.75KS4 BTEC Vocational WL 23-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 12KS4 Religious Stud WL18-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 11KS4 English Lang WL 17-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 11KS4 English Lit WL 17-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 12KS4 Maths WL 17-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 13KS4 Science Trilogy WL18-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 1-1Difference English Lan PGTG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 1-1Difference Religious StPGTG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff BTEC Voc PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 1-1Difference English Lit PGTG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 11KS4 Geography WL18-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff RS PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 11.75KS4 BTEC Workskills WL 23-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff EngLit PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff Geog PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff Maths PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff BTEC WrkSklls PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff Hospitality PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 11Difference Science Tril PG TG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Difference BTEC Voc PG TG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Difference BTEC Workskil PGTG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff Scien Tril PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Diff EngLan PG to Expected
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10Difference MathsPGTG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 10KS4 Hospitality Award WL 24-25
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 1-1Difference GeographyPGTG
04214cde-aec9-40a2-b27a-a69098ee74c3Year 11 Predicted 1-3Difference Hospitality PG to TG

 

2 ACCEPTED SOLUTIONS

Thank you once again @amustafa 

Your residuals do not quite calculate correctly.

pconridge_0-1705861255949.png

As you can see the average grade of the student is 5.44.  In English for example 5-5.44 is -0.44 not the -0.5 calculated.  I cant work out how to adapt your code to get the correct value.  Any ideas?

 

 

View solution in original post

amustafa
Solution Sage
Solution Sage

@pconridge Thank you for clarifying how you want to calculate the Risidual value. Here's the updated DAX. You can download the pbix file form my shared folder as well.

 

Residual =
VAR SelectedStudent = SELECTEDVALUE(AssessmentY11[Student])
VAR CurrentAspect = SELECTEDVALUE(AssessmentY11[Aspect])

VAR OverallAvgGrade =
    CALCULATE(
        AVERAGE(AssessmentY11[Grade Value]),
        FILTER(
            ALL(AssessmentY11),
            AssessmentY11[Student] = SelectedStudent &&
            AssessmentY11[Result Set] = "Year 11 Predicted 1"
        )
    )

VAR GradeCurrentSubject =
    CALCULATE(
        AVERAGE(AssessmentY11[Grade Value]),
        FILTER(
            ALL(AssessmentY11),
            AssessmentY11[Student] = SelectedStudent &&
            AssessmentY11[Aspect] = CurrentAspect &&
            AssessmentY11[Result Set] = "Year 11 Predicted 1"
        )
    )

RETURN
IF(
    NOT ISBLANK(GradeCurrentSubject) && NOT ISBLANK(OverallAvgGrade),
    GradeCurrentSubject - OverallAvgGrade,
    BLANK()
)
 
amustafa_0-1705918230922.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
amustafa
Solution Sage
Solution Sage

@pconridge Thank you for clarifying how you want to calculate the Risidual value. Here's the updated DAX. You can download the pbix file form my shared folder as well.

 

Residual =
VAR SelectedStudent = SELECTEDVALUE(AssessmentY11[Student])
VAR CurrentAspect = SELECTEDVALUE(AssessmentY11[Aspect])

VAR OverallAvgGrade =
    CALCULATE(
        AVERAGE(AssessmentY11[Grade Value]),
        FILTER(
            ALL(AssessmentY11),
            AssessmentY11[Student] = SelectedStudent &&
            AssessmentY11[Result Set] = "Year 11 Predicted 1"
        )
    )

VAR GradeCurrentSubject =
    CALCULATE(
        AVERAGE(AssessmentY11[Grade Value]),
        FILTER(
            ALL(AssessmentY11),
            AssessmentY11[Student] = SelectedStudent &&
            AssessmentY11[Aspect] = CurrentAspect &&
            AssessmentY11[Result Set] = "Year 11 Predicted 1"
        )
    )

RETURN
IF(
    NOT ISBLANK(GradeCurrentSubject) && NOT ISBLANK(OverallAvgGrade),
    GradeCurrentSubject - OverallAvgGrade,
    BLANK()
)
 
amustafa_0-1705918230922.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amustafa
Solution Sage
Solution Sage

try...

 

Residual =
VAR SelectedStudent = SELECTEDVALUE(AssessmentY11[Student])
VAR CurrentAspect = SELECTEDVALUE(AssessmentY11[Aspect])

VAR AvgGradeOtherSubjects =
    CALCULATE(
        AVERAGE(AssessmentY11[Grade Value]),
        FILTER(
            ALL(AssessmentY11),
            AssessmentY11[Student] = SelectedStudent &&
            AssessmentY11[Aspect] <> CurrentAspect &&
            AssessmentY11[Result Set] = "Year 11 Predicted 1"
        )
    )

VAR GradeCurrentSubject =
    CALCULATE(
        AVERAGE(AssessmentY11[Grade Value]),
        FILTER(
            ALL(AssessmentY11),
            AssessmentY11[Student] = SelectedStudent &&
            AssessmentY11[Aspect] = CurrentAspect &&
            AssessmentY11[Result Set] = "Year 11 Predicted 1"
        )
    )

RETURN
IF(
    NOT ISBLANK(GradeCurrentSubject),
    GradeCurrentSubject - AvgGradeOtherSubjects,
    BLANK()
)
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you @amustafa foryour help.  Much appreciated.  Unfortunately the measure doesnt quite work as can be seen below. 

pconridge_0-1705433484641.png

 

This might be because there are other aspects up against the year 11 predicted 1 result set.  Is it possible to adapt your DAX to only perform the residual calculation where the aspect is one of the following list? 

AssessmentY11[aspect] IN { "KS4 Art WL18-24","KS4 Art WL18-25""KS4 Biology WL18-25","KS4 BTEC Art and Design WL 24","KS4 BTEC Sport WL 24-25","KS4 BTEC Tech DIT WL 24-25","KS4 BTEC Vocational WL 23-25","KS4 BTEC Workskills WL 23-25","KS4 Business Studies WL 19-25","KS4 Chemistry WL18-25","KS4 Computer Science WL 20-25","KS4 Design Tech WL 19-25","KS4 Drama WL18-25","KS4 Engineering Award WL 24-25","KS4 English Lang WL 17-25","KS4 English Lit WL 17-25","KS4 Food and Nutrition WL 21-25","KS4 French WL18-24","KS4 Geography WL18-25","KS4 History WL18-25","KS4 Hospitality Award WL 20-23",
"KS4 Hospitality Award WL 24-25","KS4 Maths WL 17-25","KS4 Media Studies WL 19-25","KS4 Music WL18-25","KS4 Physics WL18-25","KS4 Religious Stud WL18-25","KS4 Science Trilogy WL18-25","KS4 Spanish WL 18-25","KS4 SPE WL18-25"

Hi @pconridge ,

 

I did use the data you provided and filter the results but I have different Residual values. See my file sin my shared drive.

 

AssessmentY11

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you once again @amustafa 

Your residuals do not quite calculate correctly.

pconridge_0-1705861255949.png

As you can see the average grade of the student is 5.44.  In English for example 5-5.44 is -0.44 not the -0.5 calculated.  I cant work out how to adapt your code to get the correct value.  Any ideas?

 

 

Thank you so much for your help with this @amustafa   You are a superstar.  I am really grateful.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.