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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rbustamante
Helper I
Helper I

How to calculate row number

Hello,

I have a table with the products quantity sales. 

rbustamante_0-1644880086053.png

 

In the example I have product A that repeats 3 times and it is rank 1, product B repeats 2 times and it's rank 2 and finally product C repeats 1 one time, so it's rank 3.

rbustamante_1-1644880230816.png

 

The question it is: how to calculate the rank or row number?

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Write these measures:

Instances = countrows(Data)
Rank = RANKX(ALL(Data[Product]),[Instances])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
TheoC
Super User
Super User

Hi @rbustamante 

 

First, create column / measure for the count of category:

 

Measure / Column = CALCULATE ( COUNTROWS ( 'Table' ) , ALLEXCEPT ( 'Table' , Table[Product] ) )
 
Then use a RANKX
 
Rank = RANKX ( 'Table' , Table[Column] )
 
If you want a single measure, you can use the following:
 
Measure = 

VAR _1 = CALCULATE ( COUNTROWS ( 'Table' ) , ALLEXCEPT ( 'Table' , Table[Product] ) )
VAR _2 = RANKX ( 'Table' , 'Table'[Rank] )

RETURN

_2
If you have more data that results in ties and you don't want this, just adjust the RANKX component of the column or measure to:
 
RANKX ( 'Table' , 'Table'[Column] , , ASC , Dense )
 
Hope this helps.
Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

CNENFRNL
Community Champion
Community Champion

Flexible solution,

CNENFRNL_0-1644896192097.png

 

Excel worksheet formula is enough

CNENFRNL_1-1644896249128.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

TheoC
Super User
Super User

Hi @rbustamante 

 

First, create column / measure for the count of category:

 

Measure / Column = CALCULATE ( COUNTROWS ( 'Table' ) , ALLEXCEPT ( 'Table' , Table[Product] ) )
 
Then use a RANKX
 
Rank = RANKX ( 'Table' , Table[Column] )
 
If you want a single measure, you can use the following:
 
Measure = 

VAR _1 = CALCULATE ( COUNTROWS ( 'Table' ) , ALLEXCEPT ( 'Table' , Table[Product] ) )
VAR _2 = RANKX ( 'Table' , 'Table'[Rank] )

RETURN

_2
If you have more data that results in ties and you don't want this, just adjust the RANKX component of the column or measure to:
 
RANKX ( 'Table' , 'Table'[Column] , , ASC , Dense )
 
Hope this helps.
Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Ashish_Mathur
Super User
Super User

Hi,

Write these measures:

Instances = countrows(Data)
Rank = RANKX(ALL(Data[Product]),[Instances])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
TheoC
Super User
Super User

Hi @rbustamante 

 

First, create column / measure for the count of category:

 

Measure / Column = CALCULATE ( COUNTROWS ( 'Table' ) , ALLEXCEPT ( 'Table' , Table[Product] ) )
 
Then use a RANKX
 
Rank = RANKX ( 'Table' , Table[Column] )
 
If you want a single measure, you can use the following:
 
Measure = 

VAR _1 = CALCULATE ( COUNTROWS ( 'Table' ) , ALLEXCEPT ( 'Table' , Table[Product] ) )
VAR _2 = RANKX ( 'Table' , 'Table'[Rank] )

RETURN

_2
If you have more data that results in ties and you don't want this, just adjust the RANKX component of the column or measure to:
 
RANKX ( 'Table' , 'Table'[Column] , , ASC , Dense )
 
Hope this helps.
Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.