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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
lsutula
New Member

Calculate average of maximum per category

Hi guys,

I'm struggling to find a solution to the challenge I've got at work. Perhaps you could help me.

 

I have a table of student IDs, course IDs, and grades, and need to calculate the average of grades for each student.

There's one caveat - some students repeated courses and therefore they have more than one grade per course ID. I need to find the highest grade for each course, and then use only those grades to calculate the average for a student.

 

Columns in the table:

LearnerID / Course ID / Grade

 

I was able to create a metric to find me the maximum Grade per Course ID, but I can't find a way to use those values as an input to the average function.

 

Appreciate any hints!

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @lsutula 

 

It’s my pleasure to answer for you.

According to your description,I think you can create a measure to calculate the desired result.

Like this:

Measure 3 =
AVERAGEX (
    SUMMARIZE (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[term] <= SELECTEDVALUE ( 'Table'[term] )
        ),
        'Table'[coursecode],
        "aa", MAX ( 'Table'[grade] )
    ),
    [aa]
)

v-janeyg-msft_0-1604314158026.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

View solution in original post

3 REPLIES 3
v-janeyg-msft
Community Support
Community Support

Hi, @lsutula 

 

It’s my pleasure to answer for you.

According to your description,I think you can create a measure to calculate the desired result.

Like this:

Measure 3 =
AVERAGEX (
    SUMMARIZE (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[term] <= SELECTEDVALUE ( 'Table'[term] )
        ),
        'Table'[coursecode],
        "aa", MAX ( 'Table'[grade] )
    ),
    [aa]
)

v-janeyg-msft_0-1604314158026.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

amitchandak
Super User
Super User

@lsutula , Try measures like

AverageX(values(Table[Course ID]), calculate(Max(Table[Grade])))
or
AverageX(Summarize(Table, Table[LearnerID ], Table[Course ID],"_1", calculate(Max(Table[Grade]))),[_1])

Thank you!

Both of your suggestions worked! I have another challenge to solve with that data, maybe you could also help 🙂

I need to calculate the cumulative average for each month, which means I need to average all grades until (including) month X.

The challenge though is how to pick only the highest grade for a repeated course.

Let me explain with an example:

example.png

Learner has completed BUS 5010 course in December 2019 with grade 2.00, but then retake the same course in February 2020 and got better grade: 3.00.

Therefore, his cumulative GPA should be the following:

December 2019: 2.00 (only one course, and only one grade, simple)

February 2020: 3.00 (here's the challenge - the leaner took the same course and got a better grade, so we should drop the lower grade and use only the higher, 3.00)

March 2020: 3.50 ((3.00+4.00) / 2 = 3.50)

April 2020: 3.33 ((3.00+4.00+3.00) / 3 = 3.33)

May 2020: 3.25 ((3.00+4.00+3.00+3.00) / 4 = 3.25)

You'll notice the learner took course OPM6090 twice. Once in July 2020 (scored 3.00) and then in September 2020 (scored 4.00). We should use score 3.00 until August in the cumulative average calculation, but as of September use the higher grade: 4.00 instead of 3.00.

Uff, hope this makes sense. Would be amazing if you have an idea of how to calculate such a cumulative average.

Thanks!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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