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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Rank decimal values using DAX

Is there a way to rank decimal values using DAX?
I'm trying to rank the decimal values of the measure 'Random values' but i'm not getting the rank correctly.

Measure used:

Rank of random values = RANKX( ALL(Table1),[Random values],,ASC)
 

may_bi_0-1635430612144.png

 

2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

RANKX is hard. I'm pretty good with DAX but rarely get it right on the first try.

 

Standard RANKX:

RANKX ( ALL ( Table1[Name] ), [Random values],, ASC)

The key here is iterating over distinct names rather than all of the rows of Table1. 

 

@Greg_Deckler's suggested approach is more like this:

Rank of random values = 
VAR CurrValue = [Random Values]
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                ALL ( Table1 ),
                Table1[Name],
                "Value", [Random Values]
            ),
            [Value] <= CurrValue
        )
    )

 

To me, this is a bit more intuitive than either of those above:

Rank of random values =
RANKX (
	SUMMARIZE ( ALL ( Table1 ), Table1[Name] ),
	[Random Values],
	, ASC
)

 

View solution in original post

Greg_Deckler
Community Champion
Community Champion

@Anonymous I just mocked this up because I was curious. I'm wondering if the problem lies in your [Random value] measure? Because when I put the information above in a table as columns I got the right answer:

Measure Rank of random values = RANKX( ALL(Table5),CALCULATE(SUM([Random values])),,ASC)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@Anonymous I just mocked this up because I was curious. I'm wondering if the problem lies in your [Random value] measure? Because when I put the information above in a table as columns I got the right answer:

Measure Rank of random values = RANKX( ALL(Table5),CALCULATE(SUM([Random values])),,ASC)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Did you mock it up where the table had more than one row per Name? I'm assuming [Random values] is an aggregate over multiple rows rather than a single value.

@AlexisOlson Hmm, good point, I just had single rows for each Name. It's so hard to know exactly how someone's data is setup! But, it definitely isn't that RANKX can't handle ranking decimal numbers, that's what I was curious about.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
AlexisOlson
Super User
Super User

RANKX is hard. I'm pretty good with DAX but rarely get it right on the first try.

 

Standard RANKX:

RANKX ( ALL ( Table1[Name] ), [Random values],, ASC)

The key here is iterating over distinct names rather than all of the rows of Table1. 

 

@Greg_Deckler's suggested approach is more like this:

Rank of random values = 
VAR CurrValue = [Random Values]
RETURN
    COUNTROWS (
        FILTER (
            SUMMARIZE (
                ALL ( Table1 ),
                Table1[Name],
                "Value", [Random Values]
            ),
            [Value] <= CurrValue
        )
    )

 

To me, this is a bit more intuitive than either of those above:

Rank of random values =
RANKX (
	SUMMARIZE ( ALL ( Table1 ), Table1[Name] ),
	[Random Values],
	, ASC
)

 

Greg_Deckler
Community Champion
Community Champion

@Anonymous Try doing it without RANKX: (1) To *Bleep* with RANKX! - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.