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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

RANKX issue

i am trying to do a ranking by total and by months but for some reaosn when i am doing the ranking i am geting rankings for months that havent even happened please see below;

 

Superdeathmonke_0-1597655207015.png

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Please create measures like this.

Measure = 
CALCULATE(
    SUM(Sales[Sale 2014]),
    FILTER(
        ALL(Sales),
        Sales[Month] = MAX(Sales[Month]) && Sales[CountryRegion] = MAX(Sales[CountryRegion])
    )
)
Measure 2 = 
VAR x =  
RANKX(
    FILTER( ALLSELECTED(Sales), Sales[Month] = MAX(Sales[Month]) ),
    [Measure],
    , ASC, Dense
)
VAR y =  
RANKX(
    FILTER( ALLSELECTED(Sales), Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
    [Measure],
    , ASC, Dense
)
RETURN
IF(
    HASONEFILTER(Sales[CountryRegion]),
    x, y
)

v-lionel-msft_0-1598427825410.png

 

Best regards,
Lionel Chen

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

 

View solution in original post

11 REPLIES 11
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

Like this?

v-lionel-msft_0-1597718231072.png

Measure = 
CALCULATE(
    SUM(Sales[Sale 2014]),
    FILTER(
        ALL(Sales),
        Sales[Month] = MAX(Sales[Month])&& Sales[CountryRegion] = MAX(Sales[CountryRegion])
    )
)
Measure 2 = 
RANKX(
    FILTER( ALLSELECTED(Sales), Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
    [Measure],
    , ASC, Dense
)

Or like this?

v-lionel-msft_1-1597718671140.png

Measure 3 = 
CALCULATE(
    SUM(Sales[Sale 2014]),
    FILTER(
        ALL(Sales),
        Sales[Month] = MAX(Sales[Month])
    )
)
Measure 4 = 
RANKX(
    FILTER( ALLSELECTED(Sales),Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
    [Measure 3],
    , ASC, Dense
)

 

Best regards,
Lionel Chen

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

 

 

Anonymous
Not applicable

@v-lionel-msft thank you for this, so the way i am looking to do it, is if you added your country to sit below the month on the left of matrix, you would have your ranking by month but whne you open up the month it then will give you the ranking for the countries in that month so based on the 4 countries it would rank them 1 to 4 then if i was to drill into the the country i could then get more infornation etc

 

Hi @Anonymous ,

 

Please create measures like this.

Measure = 
CALCULATE(
    SUM(Sales[Sale 2014]),
    FILTER(
        ALL(Sales),
        Sales[Month] = MAX(Sales[Month]) && Sales[CountryRegion] = MAX(Sales[CountryRegion])
    )
)
Measure 2 = 
VAR x =  
RANKX(
    FILTER( ALLSELECTED(Sales), Sales[Month] = MAX(Sales[Month]) ),
    [Measure],
    , ASC, Dense
)
VAR y =  
RANKX(
    FILTER( ALLSELECTED(Sales), Sales[CountryRegion] = MAX(Sales[CountryRegion]) ),
    [Measure],
    , ASC, Dense
)
RETURN
IF(
    HASONEFILTER(Sales[CountryRegion]),
    x, y
)

v-lionel-msft_0-1598427825410.png

 

Best regards,
Lionel Chen

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

 

amitchandak
Super User
Super User

@Anonymous , You need rank for month ?

Can you share sample data and sample output in table format?

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
harshnathani
Community Champion
Community Champion

HI @Anonymous ,

 

Try measure like

 

Measure = IF ([Total] <> BLANK() , RANKX ......  ))

 

Also, if you can share sample data.

 

For Ranks pls refer these articles

 

https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

 

 

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

Thanks @harshnathani any idea how i could do the change of ranking by month piece?

@Anonymous , you have use isinscope and change ranking

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

 

example

Rank1 = Rankx(all(Table[Month]),[Sales])

Rank2 = Rankx(all(Table[Date]),[Sales])

 

SWITCH (
TRUE,
ISINSCOPE ( Table[Month] ), [Rank1],
ISINSCOPE ( Table[Date] ), [Rank2],
[Rank3]
)

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak so in my matrix i am trying to Rank with i have Username/Month/Region/Category then i want to rank by the total sales. But when i add my currently measure of rank Rankx(ALL(Username),[Total Sales]) it gets confused and just displays ones when i drill down from username to month then region and category. I have tried to use isinscope but can't see to get it working

HI @Anonymous ,

 

 

Try DateADD function to rank for last month.

 

Then calculate the difference.

 

Regards,

Harsh Nathani

You can refer below article to get the best use cases of ranking and detailed explainations.

 

https://www.daxpatterns.com/ranking/







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




Anonymous
Not applicable

Hi @Anonymous ,

 

You can try to use the below measure to do the rank:

 

Measure = RANKX(filter(all(month),your_rank_measure > 0),your_rank_measure,,desc)

 

Please try.

 

If it's not what you want, please show some sample data and your data model.

 

Thanks.

Aiolos Zhao 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

October NL Carousel

Fabric Community Update - October 2024

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