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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rflook
Helper II
Helper II

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

@rflook 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.

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

@rflook 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

@rflook 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.

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

@rflook 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.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.