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
Ania26
Helper III
Helper III

Sorting by the last column

Hello,

 

CountryValueYear

USA12023
France32023
Canada12023
USA22024
France12024
Canada62024

 

For the data above , I have amtrix table:

Ania26_0-1741768826363.png

How can I sort by the last column? 2024. descending? 

1 ACCEPTED SOLUTION
freginier
Super User
Super User

Hey there!

 

You could try creating a Sort Column in Power Query

  • Since the matrix does not allow direct sorting by specific columns, create a calculated column:
  • In Power Query, add a new column:
    SortColumn = 'YourTable'[2024] // Ensure this refers to the 2024 column
  • Sort the Matrix Table Using This Column

    • Go to the Fields pane in Power BI.
    • Click on the Country column.
    • Select Sort by Column → Choose SortColumn.
  • Ensure Sorting Order

    • If the sort is incorrect, adjust sorting in Visual Level Filters:
      • Click on the matrix table.
      • Under Sorting & Filtering options, select 2024 columnSort Descending.

If sorting directly is not working, create a DAX measure to rank countries based on the 2024 values:

Rank2024 = RANKX(ALL('YourTable'), SUM('YourTable'[2024]), , DESC, DENSE)

Then, sort the matrix by Rank2024 instead.

 

Hope this helps!

😁😁

 

View solution in original post

6 REPLIES 6
v-echaithra
Community Support
Community Support

Hi @Ania26 ,

We wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Regards,
Chaithra.



v-echaithra
Community Support
Community Support

Hi @Ania26 ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Regards,
Chaithra E

v-echaithra
Community Support
Community Support

Hi @Ania26 ,

We wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Regards,
Chaithra.

v-echaithra
Community Support
Community Support

Hi @Ania26 ,

Thank you for reaching out to Microsoft Community.

Try to make sorting dynamic, based on the latest visible year in the matrix. So you can dynamically pick the latest visible year (e.g., 2024 now, maybe 2025 later), sort countries by their value in that latest year.

 

Create a measure to identify the latest visible year:

LatestVisibleYear =

MAX('Table'[Year])

 

and now create a measure to return value for the latest visible year to calculate the sum of values only for the latest visible year, dynamically.

 

ValueforlatestYear =

VAR LatestYear = CALCULATE(MAX('Table'[Year]), ALLSELECTED('Table'))

RETURN

CALCULATE(

SUM('Table'[Value]),

'Table'[Year] = LatestYear

)

 

Use this measure to sort your matrix, sort the matrix by ValueforlatestYear descending.

If this issue has been resolved, consider accepting helpful replies as solutions.

Regards,
Chaithra E.


Ania26
Helper III
Helper III

Hello, Thank you for this but this will not work when someone will filter other than 2024 year. 

freginier
Super User
Super User

Hey there!

 

You could try creating a Sort Column in Power Query

  • Since the matrix does not allow direct sorting by specific columns, create a calculated column:
  • In Power Query, add a new column:
    SortColumn = 'YourTable'[2024] // Ensure this refers to the 2024 column
  • Sort the Matrix Table Using This Column

    • Go to the Fields pane in Power BI.
    • Click on the Country column.
    • Select Sort by Column → Choose SortColumn.
  • Ensure Sorting Order

    • If the sort is incorrect, adjust sorting in Visual Level Filters:
      • Click on the matrix table.
      • Under Sorting & Filtering options, select 2024 columnSort Descending.

If sorting directly is not working, create a DAX measure to rank countries based on the 2024 values:

Rank2024 = RANKX(ALL('YourTable'), SUM('YourTable'[2024]), , DESC, DENSE)

Then, sort the matrix by Rank2024 instead.

 

Hope this helps!

😁😁

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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