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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Unique Rank for column

Hey all,

 

Im trying to create Unique rank(Ordinal), like the row_nubmber() function in Sql server.

Data set example:

Sub-CategoryValueRANKXTarget Rank
A1011
B922
C833
D744
E745
F746
G457
H368
I369

 

I saw the RADACAD blog about that:
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
But I do not use a Date field.

Any suggestions for the Target rank?

Thanks 🙂 

2 ACCEPTED SOLUTIONS
FrankAT
Community Champion
Community Champion

Hi @Anonymous 

with a calculated column you can do it like this :

 

11-09-_2020_23-43-52.png

 

Distinct Rank without Ties = 
VAR _Rank = RANKX(ALL('Table'),'Table'[Value],,DESC)
VAR _CountIfExists = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Value] = EARLIER('Table'[Value]) && 'Table'[Sub-Category] <= EARLIER('Table'[Sub-Category]))) - 1
RETURN
    _Rank + _CountIfExists

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

You may create two measures as below.

R = 
var r1 = 
RANKX(
   ALL('Table'),
   CALCULATE(SUM('Table'[Value]))
)
var r2 = 
RANKX(
    FILTER(
       ALL('Table'),
       'Table'[Value]=SELECTEDVALUE('Table'[Value])
    ),
    CALCULATE(MAX('Table'[Sub-Category])),,ASC
)
return
r1*100+r2

Rank = 
RANKX(
    ALL('Table'),
    [R]
)

 

Result:

a2.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

You may create two measures as below.

R = 
var r1 = 
RANKX(
   ALL('Table'),
   CALCULATE(SUM('Table'[Value]))
)
var r2 = 
RANKX(
    FILTER(
       ALL('Table'),
       'Table'[Value]=SELECTEDVALUE('Table'[Value])
    ),
    CALCULATE(MAX('Table'[Sub-Category])),,ASC
)
return
r1*100+r2

Rank = 
RANKX(
    ALL('Table'),
    [R]
)

 

Result:

a2.png

 

Best Regards

Allan

 

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

FrankAT
Community Champion
Community Champion

Hi @Anonymous 

with a calculated column you can do it like this :

 

11-09-_2020_23-43-52.png

 

Distinct Rank without Ties = 
VAR _Rank = RANKX(ALL('Table'),'Table'[Value],,DESC)
VAR _CountIfExists = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Value] = EARLIER('Table'[Value]) && 'Table'[Sub-Category] <= EARLIER('Table'[Sub-Category]))) - 1
RETURN
    _Rank + _CountIfExists

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

Anonymous
Not applicable

Hey @FrankAT ,

 

I found on the internet the answer - 

All I needed to do is to add a Random Var and add it to the Rank.

 

Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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