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
Anonymous
Not applicable

RANKX as calculated column based on column

Hi everyone! 

 

I have data in a table with columns such as below:

 

Country (all unique)Score (calculated column)
A5
B3
C2

 

My end goal is to have rank in a column as I need to create other columns off of it:

 

Country (all unique)Score (calculated col)Rank (calculated col)Top2 (calculated col)
A51A
B32B
C23All Other

 

I tried: Rank = rankx(Table,[Score]). I also thres in allselected, calculate, sum, etc but am getting all 1s in return. 

 

Would appreciate any help as I'm a total beginner! Thank you! 

6 REPLIES 6
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Column:

Rank = RANKX('Table',[Score])
Top2 = IF([Rank]<=2,[Country],"All Other")

vzhangti_0-1653026418425.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

Anonymous
Not applicable

This worked! However, is there any way to make it dynamic based on whatever filters are on the page? Thanks so much! 

 

Country (all unique)Score (calculated col)Rank (calculated col)Top2 (calculated col)Scale
A51ABig
B32BSmall
C23All OtherSmall

Hi, @Anonymous 

 

According to your description it should be feasible. But I need to know the output you expect, preferably with a picture to show it.

 

Best Regards

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below.

The below DAX formulas are for creating new columns.

Untitled.png

 

Rank CC = 
RANKX( Data, Data[Score],,DESC )

 

Top two CC = 
VAR toptwotable =
    SUMMARIZE ( TOPN ( 2, Data, Data[Score], DESC ), Data[Country] )
RETURN
    IF ( Data[Country] IN toptwotable, Data[Country], "All others" )

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.
Anonymous
Not applicable

Thanks for the reply! Is there any way to make this dynamic based on whatever filters are on the page? Appreciate it! 

Hi,

Thank you for your feedback.

I suggest having a measure, instead of creating calculated column.

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Untitled.png

 

Top two measure = 
VAR toptwotable =
    SUMMARIZE ( TOPN ( 2, ALLSELECTED( Data ), [Score measure:], DESC ), Data[Country] )
RETURN
    IF (
        HASONEVALUE ( Data[Country] ),
        IF (
            VALUES ( Data[Country] ) IN toptwotable,
            VALUES ( Data[Country] ),
            "All others"
        )
    )

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
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.