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
NotAHobbyBI
New Member

RANKX of a dimensions, based on Measure

Hi guys,

 

I'm having a little trouble around the use of the RANKX function. I've tried some videos/answers here but I feel like I'm missing something obvious, please be gentle!

I have two tables. Joined with a 1 - * relationship.

Call Occurance
Call_ID
Caller_ID
Call_DateTime

Caller
Caller_ID
Name
Country
(New column) Country Rank (see below)

Country Rank =
RANKX(
ALL(Caller[Country]),
CALCULATE(DISTINCTCOUNT('Call Occurance'[Call_ID]))
)



I'm placing them in a table and attempting to rank the Country, by using the Total Calls #. My expectation is for the Caller table Country Rank to have a very neatly ordered 1,2,3,4, I don't need them to change with slicer selection. But instead I'm returning all 1's for Country Rank.



Caller_IDNameCountryCountry Rank
ABC1JoeUK2
ABC2MitchUSA1
ABC3JohnUSA1
ABC4KevinUSA1
ABC5DarlaUK2
ABC6LucyUK2
ABC7RebeccaUSA1
ABC8AstridNorway3

 

Does anyone have any wisdom to suggest what's going wrong? Thanks in advance.

(edits: clarity, spelling)

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @NotAHobbyBI 
Make sure you are creating a measure not a column, then try

Country Rank =
RANKX (
    ALLSELECTED ( Caller[Country] ),
    CALCULATE ( DISTINCTCOUNT ( 'Call Occurance'[Call_ID] ) )
)

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, 

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below.

It is for creating a new column.

 

Picture1.png

 

Country call count CC = 
VAR _currentcountry = Caller[Country]
VAR _countcall =
    ADDCOLUMNS (
        Caller,
        "@countcall", COUNTROWS ( RELATEDTABLE ( 'Call Occurance' ) )
    )
VAR _groupbycountry =
    GROUPBY (
        _countcall,
        Caller[Country],
        "@countcallbycountry", SUMX ( CURRENTGROUP (), [@countcall] )
    )
RETURN
    SUMX (
        FILTER ( _groupbycountry, Caller[Country] = _currentcountry ),
        [@countcallbycountry]
    )

 

Rank country CC = 
RANKX ( Caller, Caller[Country call count CC],, DESC, DENSE )

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.

Just looking at this solution (it's far more elaborte). Would this route be suitable for workings towards a 'Top N + Others' type solution? 

@NotAHobbyBI 

But its a bit long way 🙂

tamerj1
Super User
Super User

Hi @NotAHobbyBI 
Make sure you are creating a measure not a column, then try

Country Rank =
RANKX (
    ALLSELECTED ( Caller[Country] ),
    CALCULATE ( DISTINCTCOUNT ( 'Call Occurance'[Call_ID] ) )
)

Yep. Was the measure/column difference. I'll go look up why that is.

Thank you! 

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.