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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
BlueCat
Frequent Visitor

How to sum first and RANKX after the group by ?

Hello,

 

I have a problem with RANKX(). It doesn't works as expected,I found the problem but I didn't find the solution...

Here an introduction the problem : 

 

I have this table :

 

BlueCat_1-1648711848089.png

 

I want to display it by grouping values by OP and then sum the QTY.

 

So under the "values", I right clicked on my QTY and then choose "Sum" like this :

 

BlueCat_3-1648712262638.png

 

And here is the result :

 

BlueCat_4-1648712327280.png

 

So now, I tried to add a ranking by using RANKX(), so I added a new column "RANK" with this value :

 

RANK = RANKX(all(OP_QTY), OP_QTY[QTY])

 

Here is my result : 

 

BlueCat_5-1648712592444.png

 This isn't what I expected... the OP "a" should be ranked 1 and the OP "b" should be ranked 2. But here both a ranked 3.

 

So I tried to find why... and it's because of the grouping by when I sum, the RANKX() ranks all the values first without grouping. If I choose  "don't summarize" for the QTY, you can see what he does :

 

BlueCat_6-1648712858014.png

 

And so, when I sum the qty, the table group by OP... so he sums the RANK to... that is why I have Rank 3 for OP "a" (since its 1+2).

 

So my question is : Is it possible to rank AFTER the sum ? I want this result :

 

BlueCat_7-1648713257266.png

 With this database :

 

BlueCat_8-1648713298874.png

 

Thank you in advance.

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Yes, you can do it my creating a couple of measures as below

Sum of Qty = SUM('Table'[Qty])

Ranking  = 
var currentQty = [Sum of Qty]
return RANKX( ALL('Table'[OP]), [Sum of Qty], currentQty)

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

Yes, you can do it my creating a couple of measures as below

Sum of Qty = SUM('Table'[Qty])

Ranking  = 
var currentQty = [Sum of Qty]
return RANKX( ALL('Table'[OP]), [Sum of Qty], currentQty)

Thank you 🙂

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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