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
Nicks612
Helper I
Helper I

How to generate the RANK with reference of two other columns - dynamic Ranking

hello everyone,

 

I want to generate the rank column with reference to other columns.

Please refer to the below explanation of the problem.

 

for example, for Sr.No = '123456', there are three DBKeys, So

for the smallest DBKey, the Rank column displays the '1'

for the 2nd smallest DBKey, the Rank column displays the '2'

for the 3rd smallest DBKey, the Rank column displays the '3'

 and so on...

like that, we need to do for other Sr.Nos also.

 

Table A

Sr.No

DBKey

123456

20230503092547

123456

20230503070939

123456

20230503084725

235678

20230508100137

132456

20230524172714

132456

20230527141557

165478

20230514120545

165478

20230513100529

165478

20230514153705

165478

20230514194523

165478

20230514083357

765432

20230507130646

765432

20230507131046

 

Result Table:

 

Table A

Sr.No

DBKey

Rank

123456

20230503092547

3

123456

20230503070939

1

123456

20230503084725

2

235678

20230508100137

1

132456

20230524172714

1

132456

20230527141557

2

165478

20230514120545

3

165478

20230513100529

1

165478

20230514153705

4

165478

20230514194523

5

165478

20230514083357

2

765432

20230507130646

1

765432

20230507131046

2

 

can anyone help me out? I need a solution by using DAX as well as by using a power BI query editor, if possible.

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Nicks612 ,

 

You can create a calculated column as follows.

Column = RANKX(FILTER('Table',[Sr.No]=EARLIER('Table'[Sr.No])),[DBKey],,ASC,Dense)

vstephenmsft_0-1701078170356.png

 

Best Regards,

Stephen Tao

 

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

Anonymous
Not applicable

Hi @Nicks612 ,

 

Below are the results achieved using power query editor.

 

1) First, need to group by Sr.No column.

SRIRAGAVENDRAN_0-1701083255779.png

 

2) Then add a custom column with the M code Table.AddRankColumn([All],"Ranking",{"DBKey"})

SRIRAGAVENDRAN_1-1701083282822.png

3) Then Expand the custom column by unchecking Sr.No column.

SRIRAGAVENDRAN_2-1701083335125.png

4) Remove the All Column..

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Nicks612 ,

 

Below are the results achieved using power query editor.

 

1) First, need to group by Sr.No column.

SRIRAGAVENDRAN_0-1701083255779.png

 

2) Then add a custom column with the M code Table.AddRankColumn([All],"Ranking",{"DBKey"})

SRIRAGAVENDRAN_1-1701083282822.png

3) Then Expand the custom column by unchecking Sr.No column.

SRIRAGAVENDRAN_2-1701083335125.png

4) Remove the All Column..

Thanks for the reply!! I want to know how to change the DBKey column number format to a whole number. I don't want the 2.02305E+13 format. Is there any option to convert it?  I have tried to overcome this issue by using Data Type options but have not succeeded. Please guide me on that.

Anonymous
Not applicable

Hi @Nicks612 ,

 

You can create a calculated column as follows.

Column = RANKX(FILTER('Table',[Sr.No]=EARLIER('Table'[Sr.No])),[DBKey],,ASC,Dense)

vstephenmsft_0-1701078170356.png

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors