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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to get the SUM of TOPN values where some values have an equal value?

Hi, after some kind soul on here helped me out with a TOPN issue, I have another issue that I'm hoping someone can help me with. I'm trying to sum together the top 8 achievement grades for a selected pupil. Currently I'm using the following

 

Best8List = var _top =
   TOPN(8,
        FILTER(
           'Report-Ach',
           'Report-Ach'[intGradeTransposeValue]>=5 && 'Report Ach'[intReportCycleID] = 'PupilData'[LastRepCycleID] && 'Report-Ach'[txtSchoolID] = 'PupilData'[txtSchoolID]),
       'Report-Ach'[intGradeTransposeValue],
        DESC)
return
   SUMX(_top,'Report-Ach'[intGradeTransposeValue])
 
The issue I am facing is that if a student has several grades that are the same, it includes those values in the sum. So for example if t a student's grade set was: 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, all of the 8s and all of the 9s will be included in the sum. What I actually want is for the 9s to be included, and four of the 8s. 

I thought perhaps I need to use RANKX alongwith TOPN but I'm not really sure how to do this. Can any kind soul help?
7 REPLIES 7
parry2k
Super User
Super User

@Anonymous in your measure you are using some other columns and that's what I'm trying to get to. You can just list the columns and how you want to visualize it (or calculating rank)



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Here is some sample data:

 

txtSchoolIDintReportCycleID  intGradeTransposeValue
851753944746   328  9
851753944746   328  8
851753944746   328  9
851753944746   328  9
851753944746   328  9
851753944746   328  8
851753944746   328  9
851753944746   328  9
851753944746   328  8
851753944746   328  8

 

So for this student, if we were to rank his scores, it would be 9,9,9,9,9,9,8,8,8,8. I want to sum the top 8 of these scores, so 9+9+9+9+9+9+8+8 = 70

parry2k
Super User
Super User

@Anonymous also in this case I will use the new ROWNUMBER function and that will make it super easy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous can you share sample data, also is this a column or a measure? 'Report-Ach'[intGradeTransposeValue] or



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

It's a calculated column. I could show some data if you really need it, but not until tomorrow as I can only access the data set from my work IP address. 

 

 

parry2k
Super User
Super User

@Anonymous why four of 8's what is the logic?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Well, I need the top 8 values from the student's results, so that would be four 9s and then four 8s. I just realised my TOPN was wrong in the code snippet I posted (that was after I tried to figure out what was going wrong). I have just editted it for the top 8 results. 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors