How can I use RANKX in DAX to rank customers within each region while keeping ties properly handled

0 votes

How can I use RANKX() in DAX to rank customers within each region while keeping ties properly handled?
I need a Power BI measure that ranks customers within each region using RANKX, ensuring that ties are properly handled without skipping ranks. What is the best way to structure the DAX formula to achieve correct rankings while considering filter contexts?

Mar 10 in Power BI by Evanjalin
• 22,610 points
57 views

1 answer to this question.

0 votes

The RANKX() function allows you to rank customers in each region while taking care of tied ranks. Therefore, make sure ranking is calculated over a context filtered by area, not skipping ranks due to tie situations.

DAX Measure to Rank Customers in Each Region

Customer Rank = 
RANKX(
    CALCULATETABLE( 
        VALUES( 'Customers'[CustomerName] ), 
        ALLSELECTED( 'Customers' ) 
    ),
    CALCULATE( SUM( 'Sales'[TotalSales] ) ),
    , 
    DESC, 
    DENSE
)

Explanation:

CALCULATETABLE(VALUES('Customers'[CustomerName]), ALLSELECTED('Customers'))

Creates a virtual table containing unique customers within the selected region so that ranking is done per region.

CALCULATE(SUM('Sales'[TotalSales]))

Defines the ranking criteria (total sales per customer).

RANKX(..., ..., DESC, DENSE)

DESC → Ranks in descending order (highest sales first).

DENSE → Tied values receive the same rank, while the next rank is given without skipping.

Handling Filter Context

The ranking will respect all active filters applied in the ALLSELECTED function, for instance, a particular region selected in a slicer.  

If you want to ignore all slicers that affect regions in the rankings, replace ALLSELECTED('Customers') with ALL('Customers').

This will ensure that customers are ranked properly within each region without skipping the sequence for any ties.

answered Mar 10 by anonymous
• 22,610 points

Related Questions In Power BI

0 votes
1 answer

How can I unpivot multiple columns dynamically while keeping other columns unchanged in Power Query?

To dynamically unpivot multiple columns in Power ...READ MORE

answered Mar 11 in Power BI by anonymous
• 22,610 points
82 views
0 votes
1 answer

How can I use DAX to generate a dynamic ranking that changes based on selected filters?

You can create a dynamic ranking measure ...READ MORE

answered 1 day ago in Power BI by anonymous
• 22,610 points
37 views
0 votes
1 answer

How to use Dynamic DAX Number Format in power BI?

You can give them the same display ...READ MORE

answered Dec 8, 2020 in Power BI by Gitika
• 65,770 points
2,535 views
0 votes
1 answer

How to use No QUARTER() in DAX in power BI?

One should use =ROUNDUP(MONTH([Date])/3, 0) to get quarte ...READ MORE

answered Dec 8, 2020 in Power BI by Gitika
• 65,770 points
899 views
+2 votes
0 answers

Assume referential integrity

1) What is Assume referential integrity? what ...READ MORE

Aug 19, 2019 in Power BI by vnk
1,950 views
+2 votes
1 answer

If Condition

DAX - I assume [Claim_line].[Allowed_Amount_B6] is one ...READ MORE

answered Aug 20, 2019 in Power BI by anonymous
• 33,050 points
1,754 views
+2 votes
1 answer

How to export data to CSV from power bi embedded url ?

Hi Arathi, You can open Visuals from embedded ...READ MORE

answered Aug 23, 2019 in Power BI by anonymous
• 33,050 points
6,799 views
+1 vote
1 answer

Power Bi to Machine Learning Model

Hello @vnk! Power BI only supports Azure Machine ...READ MORE

answered Dec 3, 2019 in Power BI by Priyanka
1,334 views
0 votes
1 answer

I need to calculate a running total but reset it at the start of each new quarter—how can I achieve this in DAX?

To calculate a running total that resets ...READ MORE

answered Mar 7 in Power BI by anonymous
• 22,610 points
68 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP