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
vilnyts
Frequent Visitor

Adding RAND() number to measure and RANKX() it

Hi, everyone.

I have a problem when i am using RANKX() function.

I have a one column table that contains redundant category names (AAA, BBB, CCC.....FFF) and have a measure that counts rows through a table:

Counts =
COUNT(
'table'[Dim]
)
 
I am going to rank my rows, to do that i have a measure:
RankRows =
RANKX(ALL('table'[Dim]), [Counts] ,, DESC)
 
When i put those measures (rank and count) and column into a table i have the following:
vilnyts_0-1657692232304.png

As you can see categories EEE, FFF have the same counts and as a result the same rank.

I want to get rid of this, i need to get the unique rank for the each row.

To do that, "Counts" measure was modified a bit i added random number and expected to get correct rank, but i have this:

vilnyts_1-1657692790581.png

"Counts" was modified like this:

Counts =
COUNT(
'table'[Dim]
) + DIVIDE(RAND(), 100)
 
Could somebody help or explain way, how to add to measure random number and after RANKX() through this value.
I am expecting from above example something like this:
DDD, 8, 1
CCC, 7, 2
BBB, 6, 3
AAA, 5, 4
EEE, 4, 5
FFF, 4, 6
 
Thank you in advance.
Have a good day)
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below measures and the attached pbix file.

I suggest writing an additional measure like below.

 

Rankalphabet = 
RANKX ( ALL ( 'Table'[Dim] ), CALCULATE ( MAX ( 'Table'[Dim] ) ),, ASC ) / 100

 

Counts = 
COUNT(
'Table'[Dim]
) + [Rankalphabet]

 

RankRows = 
RANKX(ALL('Table'[Dim]),  [Counts],, DESC)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
vilnyts
Frequent Visitor

Hi,

Thanks a lot Jihwan_Kim, it was the solution for me.

Have a good day.

 

Jihwan_Kim
Super User
Super User

Hi,

Please check the below measures and the attached pbix file.

I suggest writing an additional measure like below.

 

Rankalphabet = 
RANKX ( ALL ( 'Table'[Dim] ), CALCULATE ( MAX ( 'Table'[Dim] ) ),, ASC ) / 100

 

Counts = 
COUNT(
'Table'[Dim]
) + [Rankalphabet]

 

RankRows = 
RANKX(ALL('Table'[Dim]),  [Counts],, DESC)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.