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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
chiu2020
Frequent Visitor

Ranking within a group

Hi all,

 

Below matrix table is showing Parent SKU sales by customer.

 

My DAX formula can rank by Parent SKU correctly. However, I don't know how to do the correct ranking within the sub group (by customer) for each Parent SKU.

 

Rank by $ = RANKX(ALL('SKU Master'[Parent SKU]),CALCULATE('Invoiced Sales Measure'[Invoiced Sales $],ALL(Customer[Customer Group])) ,,DESC,Skip)

 

Can anyone help? Thanks.

Capture.PNG

1 ACCEPTED SOLUTION
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, and I hope the below can provide some ideas on how to create a solution for your dataset.

 

Jihwan_Kim_0-1662619929156.png

 

 

 

Sales total: = 
SUM( Sales[Sales] )


Rank by sales: =
VAR _SKUranking =
    RANKX ( ALL ( 'SKU Master'[Parent SKU] ), [Sales total:],, DESC )
VAR _CustomerslistbySKU =
    FILTER (
        SUMMARIZE ( ALL ( Sales ), Customer[Customer], 'SKU Master'[Parent SKU] ),
        'SKU Master'[Parent SKU] = MAX ( 'SKU Master'[Parent SKU] )
    )
VAR _Customersranking =
    RANKX ( _CustomerslistbySKU, [Sales total:],, DESC )
RETURN
    SWITCH (
        TRUE (),
        ISINSCOPE ( Customer[Customer] ), _Customersranking,
        ISINSCOPE ( 'SKU Master'[Parent SKU] ), _SKUranking
    )

 


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.

View solution in original post

3 REPLIES 3
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, and I hope the below can provide some ideas on how to create a solution for your dataset.

 

Jihwan_Kim_0-1662619929156.png

 

 

 

Sales total: = 
SUM( Sales[Sales] )


Rank by sales: =
VAR _SKUranking =
    RANKX ( ALL ( 'SKU Master'[Parent SKU] ), [Sales total:],, DESC )
VAR _CustomerslistbySKU =
    FILTER (
        SUMMARIZE ( ALL ( Sales ), Customer[Customer], 'SKU Master'[Parent SKU] ),
        'SKU Master'[Parent SKU] = MAX ( 'SKU Master'[Parent SKU] )
    )
VAR _Customersranking =
    RANKX ( _CustomerslistbySKU, [Sales total:],, DESC )
RETURN
    SWITCH (
        TRUE (),
        ISINSCOPE ( Customer[Customer] ), _Customersranking,
        ISINSCOPE ( 'SKU Master'[Parent SKU] ), _SKUranking
    )

 


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.

Thanks for that. It is very helpful

May I also know how to add the ranking as a slicer? Thanks.

Hi,

Thank you for your feedback. May I ask how is your ranking slicer look like and what does it do?

For instance, if it selects 3, do you want to only show ranking number 3?


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.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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