Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Rank based on multiple columns in matrix

Hello team,

 

I have a Brand & product column in heirarchy in matrix visual along with sales I want rank based on Brand If visual is not expanded and if visual is expaned then it should return rank based on product. I also have slicers on the page. 

 It should not have ties, My dataset has around 14 million rows so COUNTROWS doesn't seem to work. 

 

rankpro = IF(ISINSCOPE('Product Attributes'[Brand-Product]),RANKX(ALLSELECTED('Product Attributes'[Brand-Product]),[Sellout (P)],,DESC,Dense))
 
But it is returning ties. 

 

 

@jihwan_kim amitchandak Jihwan_Kim Anonymous Fowmy  

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Total Sales = SUM( Sales[Amount] )
    
    Ranking = 
    switch( TRUE(),
        ISINSCOPE( Products[Prod Name] ),
            var ProductsForRanking =
                CALCULATETABLE(
                    DISTINCT( Products[ProductID] ),
                    DISTINCT( Products[Brand] ),
                    ALLSELECTED( Products )
                )
            var Rank_ =
                RANKX(
                    ProductsForRanking,
                    CALCULATE(
                        [Total Sales],
                        ALLEXCEPT( Products, Products[ProductID] )
                    ), 
                    [Total Sales],
                    DESC,Dense
                )
            return
                Rank_,
    
        ISINSCOPE( Products[Brand] ),
            var BrandsForRanking =
                CALCULATETABLE(
                    DISTINCT( Products[Brand] ),
                    ALLSELECTED( Products )
                )
            var Rank_ =
                RANKX(
                    BrandsForRanking,
                    [Total Sales],,
                    DESC,Dense
                )
            return
                Rank_
    )