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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
liselotte
Helper I
Helper I

Rank a measure

I have
- a dimension table 'dim_Date' with column 'Date'

- a dimension table 'dim_Customers' with columns 'Customer ID', 'Customer Name'

- a fact table 'fact_Sales' with columns 'Customer ID', 'Date', 'Type', 'Sales'.

 

I want to create a measure to rank Customers based of their Sum of Sales over a time period which is filtered in a slicer of 'dim_Date'['Date']. This measure will be used later in a visual graph with visual filter on 'fact_Sales'['Type']. 

This is my DAX query for the measure:

 

Rank = RANKX(ALLSELECTED('fact_Sales'),CALCULATE(SUM('fact_Sales'[Sales]),ALLEXCEPT('fact_Sales','fact_Sales'[Customer ID])),,DESC,Dense)

 

 But the function ALLACCEPT in my measure ignore filters of 'dim_Date'['Date'] and 'fact_Sales'['Type'].

Could you help me with changing the query so that it doesn't ignore filters of 'dim_Date'['Date'] and 'fact_Sales'['Type'], please? Thank you 🙂

1 ACCEPTED SOLUTION
mark_endicott
Super User
Super User

@liselotte - I would use the RANK function as it is easier to understand, and has better handling of blanks. Which can cause issues with ranking. The DAX code you can use is below (you just need to change the table names):

 

Rank = RANK(DENSE, ALLSELECTED( customer[Customer ID] ), ORDERBY(CALCULATE(SUM( sales[sales] )), DESC),LAST)

 

You should then make sure you use the Customer ID from the Customer table in your visual, if you include any other columns in your visual, you will need to add them into the ALLSELECTED. 

 

This solution is dynamic because the CALCULATE will take any filters from your other dimensions, or the type from the fact. 

 

See screenshots below:

 

mark_endicott_0-1718896410304.png

 

mark_endicott_2-1718896476770.png

 

mark_endicott_1-1718896439577.png

If this works for you, please mark it as the solution.

View solution in original post

4 REPLIES 4
mark_endicott
Super User
Super User

@Sirhawk3017 - I would suggest starting a new conversation, with more details around the issue you observed, any error you recieved and the expected result.

mark_endicott
Super User
Super User

@liselotte - I would use the RANK function as it is easier to understand, and has better handling of blanks. Which can cause issues with ranking. The DAX code you can use is below (you just need to change the table names):

 

Rank = RANK(DENSE, ALLSELECTED( customer[Customer ID] ), ORDERBY(CALCULATE(SUM( sales[sales] )), DESC),LAST)

 

You should then make sure you use the Customer ID from the Customer table in your visual, if you include any other columns in your visual, you will need to add them into the ALLSELECTED. 

 

This solution is dynamic because the CALCULATE will take any filters from your other dimensions, or the type from the fact. 

 

See screenshots below:

 

mark_endicott_0-1718896410304.png

 

mark_endicott_2-1718896476770.png

 

mark_endicott_1-1718896439577.png

If this works for you, please mark it as the solution.

What if I wanted to rank based on a divide measure? I tried and it did not succeed.

 

 

Sirhawk3017_0-1724607973202.png

 

Hi @mark_endicott ,

Thank you very much for your help. It works! 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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