Forum Discussion

chiu2020's avatar
chiu2020
Frequent Visitor
4 years ago
Solved

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 (...
  • Jihwan_Kim's avatar
    4 years ago

    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.

     

     

     

     

    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
        )