Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Continued Contributor
Continued Contributor

RANKX in bar chart with legend

Hello All,
I'm struggling with RANKX. I have a table with customer master data in it, related to a table with customer usage data in it. I want to see top ten customers, for example, by page views.

It works for me when I have a bar chart, without a legend. For example, I have these measures:


Total Views =
Rank Views by Location =
    RANKX(ALLSELECTED('Customer'), [Total Views],,DESC)
I can draw the bar chart, and filter and sort on Rank Views by Location <= 10 as shown below
rank works.jpg

However, when I try to add the category as a legend, the same formulas no longer work. I suspect my DAX isn't telling Power BI to look at the full total of each location, however, I cannot figure out how to make this work and also sort properly from largest to smallest top 10.

rank not working.jpg

I've even tried changing the RANKX expression in a multitude of ways. Here's the latest, but it still doesn't work.

Rank Page Views by Location Sort =
    RANKX(ALLSELECTED('Customer'), SUMX(RELATEDTABLE('Stream'), [Total Views]),,DESC)

Again, the 'Customer' table is related -> to the 'Stream' table. However, the [Category] is on a table several relationships away from the 'Stream' table. Not sure if this is an issue?

Any ideas? @OwenAuger  @v-ljerr-msft 
Super User
Super User

RELATEDTABLE only works for calculated columns, not for measures.


Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Please show the expected outcome based on the sample data you provided.

Helpful resources

PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors