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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Rankx on a matrix

i am trying to do rankx on a matrix table but when i drill down i would like the rankx to recalculate when i drill down, currently i have the following fields in my matrix and want to do the rank by total sales. Any help would be amazing;

 

Superdeathmonke_0-1597670678499.png

 

8 REPLIES 8
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create measure like DAX below .

Endleaf Rank =
SWITCH (
    TRUE (),
    ISINSCOPE ( Sales[Username] ), RANKX (
        ALLSELECTED ( Sales[Username] ),
        CALCULATE ( SUM ( Sales[Point] ) ),
        ,
        DESC,
        DENSE
    ),
    ISINSCOPE ( Sales[Date].[Month] ), RANKX (
        ALLSELECTED ( Saless[Date].[Month] ),
        CALCULATE ( SUM ( Sales[Point] ) ),
        ,
        DESC,
        DENSE
    ),
    ISINSCOPE ( Sales[store]]] ), RANKX (
        ALLSELECTED ( Store[store] ),
        CALCULATE ( SUM ( Sales[Point] ) ),
        ,
        DESC,
        DENSE
    ),
    ISINSCOPE ( Sales[Product]]] ), RANKX (
        ALLSELECTED ( Store[Product] ),
        CALCULATE ( SUM ( Sales[Point] ) ),
        ,
        DESC,
        DENSE
    )
)

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

Anonymous
Not applicable

thanks amy, still not geting the outcome i would expect as i am still getting just loads of 1 when i drill down;

 

Superdeathmonke_0-1597745670577.png

 

Greg_Deckler
Super User
Super User

@Anonymous - https://community.powerbi.com/t5/Quick-Measures-Gallery/To-Bleep-with-RANKX/m-p/1042520#M452


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Please share sample data and expected output.

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Anonymous
Not applicable

@harshnathani currently if i am just looking at the table before i drill down from user the ranking is current using;

 

Rankx(all(username),[Total Sales])

 

but when i drill down to month it just gives me 1 on everything then when i further drill down to the other options it is always 1 when i would expect it to recalculate and rank the months then rank the next category etc

 

 

Hi @Anonymous ,

 

Since it is matrix and you need to drill down,  you will need to use ISINSCOPE.

 

See this article

 

https://www.sqlbi.com/articles/filtering-the-top-3-products-for-each-category-in-power-bi/

 

 

Regards,

Harsh Nathani

Anonymous
Not applicable

@harshnathani i have tried doing ISINSCOPE and dont get any different result it is still just giving me a 1 for everything when i drill down;

 

Endleaf Rank =
SWITCH(
TRUE(),
ISINSCOPE(Sales[Username]), RANKX(ALLSELECTED(Sales[Username]),[Total Points], ,DESC,Dense),
ISINSCOPE(Sales[Date].[Month]),RANKX(ALLSELECTED(Saless[Date].[Month]), [Total Points], ,DESC, Dense),
ISINSCOPE(Sales[store]]]), RANKX(ALLSELECTED(Store[store]),
[TotalSales], ,
DESC,
Dense)
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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