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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

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. 
raghavdevsingh_0-1625737752835.png

 

 

@jihwan_kim @amitchandak @Jihwan_Kim @Anonymous @Fowmy  

1 REPLY 1
Anonymous
Not applicable

daxer_0-1625743141434.pngdaxer_1-1625743172159.pngdaxer_2-1625743217931.png

daxer_3-1625743267985.png

daxer_4-1625743292661.png

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_
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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