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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Ania26
Helper III
Helper III

Sorting

Hello, I would like to have this measure:

Rank Total C = IF('X'[TOP N Countries TC]<> BLANK(),RANKX(TOPN(SELECTEDVALUE('TOP N Selection'[Value]),ALLSELECTED('X'),[Total Total C]),[Total Total C],,DESC,Dense))
sorting by value from recent year and then Others at the end. So for this chart:
Ania26_0-1761222293625.png

Spain should be before Poland. 

 
1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @Ania26 ,

 

You can use the 2025 year value to sort the bar chart in the descending order by creating a sorting measure like below and putting in the tooltip field.  

 

Rank by Latest Year = 
VAR CurrentCountry = SELECTEDVALUE('X'[Country]) // <-- Replace with your country column
VAR RecentYearValue = calculate([Total Amount],'Calendar'[Year]=2025) // <-- Replace with your 2025 value measure

RETURN
IF(
    CurrentCountry = "Other",
    -999999999, // A very large negative number to push "Other" to the last position
    RecentYearValue
)

Then you can click on the three dot elipsis .... and select the measure above.

DataNinja777_0-1761230074648.png

The resultant out put is as shown above which is in line with your requirement.  

 

I am attaching an example pbix file for your reference.

 

Best regards,

 

 

 

View solution in original post

3 REPLIES 3
DataNinja777
Super User
Super User

Hi @Ania26 ,

 

You can use the 2025 year value to sort the bar chart in the descending order by creating a sorting measure like below and putting in the tooltip field.  

 

Rank by Latest Year = 
VAR CurrentCountry = SELECTEDVALUE('X'[Country]) // <-- Replace with your country column
VAR RecentYearValue = calculate([Total Amount],'Calendar'[Year]=2025) // <-- Replace with your 2025 value measure

RETURN
IF(
    CurrentCountry = "Other",
    -999999999, // A very large negative number to push "Other" to the last position
    RecentYearValue
)

Then you can click on the three dot elipsis .... and select the measure above.

DataNinja777_0-1761230074648.png

The resultant out put is as shown above which is in line with your requirement.  

 

I am attaching an example pbix file for your reference.

 

Best regards,

 

 

 

Ilgar_Zarbali
Super User
Super User

Here’s a simple sort-key measure that ranks by the latest selected year and always pushes “Other” to the end:

 

Sort (RecentYear, Other last) :=
VAR RecentYear =
MAXX ( ALLSELECTED ( 'Date'[Year] ), 'Date'[Year] )
VAR ValRecentYear :=
CALCULATE ( [Total Total C], KEEPFILTERS ( 'Date'[Year] = RecentYear ) )
VAR IsOther = SELECTEDVALUE ( 'X'[Country] ) = "Other"
VAR RankRecent :=
RANKX (
ALLSELECTED ( 'X'[Country] ),
CALCULATE ( [Total Total C], KEEPFILTERS ( 'Date'[Year] = RecentYear ) ),
, DESC, DENSE
)
RETURN IF ( IsOther, 100000 + RankRecent, RankRecent )

 

Use this measure to Sort by in the visual (ellipsis › Sort by › Sort (RecentYear, Other last)).
If you also apply a Top-N, use the same RANKX expression but replace ALLSELECTED('X'[Country]) with your Top-N table.

 

 

 

Kishore_KVN
Super User
Super User

Hello @Ania26 , It sorts based on total. Please mention Year level filtering in your TOPN and that will help you to bring Spain above Poland. 

 

Mark this comment as answer if it helps you so that others can reach quickly. Thanks. 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors