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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Rankx Vs Sort By Column

Hello all,

I have a dataset like that:

MarketProduct ColorDateSales
Market ARedJanuary 20 $    9,880
Market BBlueFebruary 20 $    9,418
Market CYellowMarch 20 $    4,536
Market DBlackApril 20 $    3,027
Market BRedFebruary 20 $    4,203
Market CBlueMarch 20 $    2,303
Market BYellowApril 20 $    5,162
Market CBlueMay 20 $    3,519
Market DYellowMarch 20 $    5,336

In my reports I want the markets in a special order. For that reason I created this table:

MarketOrder
Market B1
Market A2
Market D3
Market C4

 

I've sorted "Market" column by "Order" column. And created one to many relationship between tables. Everything worked perfectly fine up to this point. But when I created a "rankx" formula, It didn't work right. I want a Matrix visual which looks like this:

 MARKET B MARKET A MARKET D MARKET C 
 SalesRankSalesRankSalesRankSalesRank
January 20 $       1,7074 $    5,0531 $    2,7932 $    2,6243
February 20 $       3,3493 $    3,4402 $    5,0381 $    2,9704
March 20 $       9,2691 $    1,9114 $    7,7723 $    9,1232
April 20 $       1,3234 $    3,2823 $    3,5802 $    4,0961

 

I wrote this formula but it didn't work with "sort by column".

Rank = RANKX ( ALLSELECTED(Data[Markets]) , CALCULATE ( SUM(Data[Sales])), , DESC)

Can anyone please help me? Any solution will be welcomed 🙂

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

If you are using the Market column from your sort table and you have sorted that column by the Order column, you'll need an expression like this.  Replace MarketSort with the actual name of that table.

 

MarketRank =
RANKX (
    ALLSELECTED ( MarketSort[Market], MarketSort[Order] ),
    CALCULATE ( SUM ( Markets[Sales] ) ),
    ,
    DESC
)

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

If you are using the Market column from your sort table and you have sorted that column by the Order column, you'll need an expression like this.  Replace MarketSort with the actual name of that table.

 

MarketRank =
RANKX (
    ALLSELECTED ( MarketSort[Market], MarketSort[Order] ),
    CALCULATE ( SUM ( Markets[Sales] ) ),
    ,
    DESC
)

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thank you very much. It totally worked 👍

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.