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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Matt78
Helper II
Helper II

Ranking customers by sales, top seller shown as #2

Hi

 

I have DAX string here where I want to simply rank customers by sales and have ranking #.

RANK = RANKX(ALL('CustomerTable'[BUSINESS_UNIT_NAME_FI]),[Total Sales],,DESC)
 
This works fine if I have use a matrix where all customers are listed BUT if I filter this to show only one customer and would like to see what is the rank, it shows the highest selling customer as #2 and second best selling as #3. I suppose it thinks #1 is total sales..?
How should I fix my DAX so that when I filter customers one by one, it gives the correct rank?

BR
Matt
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @rajendraongole1 , please allow me to provide another insight:

Hi  @Matt78 ,

I created some data:

vyangliumsft_2-1717568810997.png

 

Here are the steps you can follow:

1. Create measure.

True_Measure =
var _table1=
SUMMARIZE(
    ALL('CustomerTable'),[Customer],"Total Sales Measure",[Total Sales])
var _table2=
ADDCOLUMNS(
    _table1,"Rank",RANKX(_table1,[Total Sales Measure],,DESC))
return
MAXX(
    FILTER(_table2,[Customer]=MAX('CustomerTable'[Customer])),[Rank])

2. Result:

Before filtering:

vyangliumsft_0-1717568751776.png

 

After filtering:

vyangliumsft_1-1717568751777.png

 

Best Regards,

Liu Yang

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

View solution in original post

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Hi  @Matt78 ,

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Liu Yang

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

v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @rajendraongole1 , please allow me to provide another insight:

Hi  @Matt78 ,

I created some data:

vyangliumsft_2-1717568810997.png

 

Here are the steps you can follow:

1. Create measure.

True_Measure =
var _table1=
SUMMARIZE(
    ALL('CustomerTable'),[Customer],"Total Sales Measure",[Total Sales])
var _table2=
ADDCOLUMNS(
    _table1,"Rank",RANKX(_table1,[Total Sales Measure],,DESC))
return
MAXX(
    FILTER(_table2,[Customer]=MAX('CustomerTable'[Customer])),[Rank])

2. Result:

Before filtering:

vyangliumsft_0-1717568751776.png

 

After filtering:

vyangliumsft_1-1717568751777.png

 

Best Regards,

Liu Yang

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

Hi

 

With this I get the following result:

 

Matt78_0-1717570770902.png

 

 

br

Matt

 

rajendraongole1
Super User
Super User

Hi @Matt78 - I have done slight modification to your measure can you try the below measure, allselected ensures ranking considers the current filters except for the context of the current row.

 

RANK = RANKX(
ALLSELECTED('CustomerTable'[BUSINESS_UNIT_NAME_FI]),
[Total Sales],
,
DESC,
DENSE
)

 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi,

 

When I have all customers listed it ranks ok but still if I filter to only one customer, it gives #1 rank to every customer

 

br

Matt

Hi @Matt78 - Can you try the below refined measure

Customer Rank =
IF(
ISFILTERED('Customers'[CustomerID]),
RANKX(
ALL('Customers'[CustomerID]),
CALCULATE(SUM('Sales'[Amount]))
),
RANKX(
ALLSELECTED('Customers'[CustomerID]),
CALCULATE(SUM('Sales'[Amount]))
)
)

 

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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