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
rynhowl
Microsoft Employee
Microsoft Employee

Summarize a summarize

How do I do this SQL query in DAX? I've searched the forums; I don't know if I'm just searching the wrong terms or what, but I can't find anything that works.

 

SELECT

    AVG(SumOfMaxGrades) AS ClassAverageGrade

FROM (

    SELECT

        Student,

        SUM(MaxGrade) AS SumOfMaxGrades

    FROM (

        SELECT

            Student,

            Assignment,

            MAX(Grade) AS MaxGrade

        FROM TableA

        GROUP BY Student, Assignment

    ) B

    GROUP BY Student

) C

 

Additional context if needed: In the example, I have students who get mutliple attempts on each assignment and only the max score is kept for each one, then their final grade is the sum of all assignment grades, and I want to find the class average. (Please don't try to correct my grading logic here, this is a made up example, the actual dataset has nothing to do with grading.)

 

StudentAssignmentGrade
Bob190
Bob195
Bob285
Bob287
Sally192
Sally188
Sally270
Sally275
John145
John150
John165
John265
John270

 

StudentAssignmentMax Grade
Bob195
Bob287
Sally192
Sally275
John165
John270

 

Student

Sum of assignment grades

Bob182
Sally167
John135

 

Class Average Grade: 161.33

 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @rynhowl 

 

Try this measure:

Class Average Grade =
VAR _A =
    SUMMARIZE (
        'Table',
        'Table'[Student],
        'Table'[Assignment],
        "Max Grade", MAX ( 'Table'[Grade] )
    )
VAR _B =
    SUMX ( _A, [Max Grade] ) / COUNTROWS ( VALUES ( 'Table'[Student] ) )
RETURN
    _B

 

Output:

VahidDM_0-1666911477091.png

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

Hi @rynhowl 

 

Try this measure:

Class Average Grade =
VAR _A =
    SUMMARIZE (
        'Table',
        'Table'[Student],
        'Table'[Assignment],
        "Max Grade", MAX ( 'Table'[Grade] )
    )
VAR _B =
    SUMX ( _A, [Max Grade] ) / COUNTROWS ( VALUES ( 'Table'[Student] ) )
RETURN
    _B

 

Output:

VahidDM_0-1666911477091.png

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

rynhowl
Microsoft Employee
Microsoft Employee

Thank you, this was a good idea 🙂

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.