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

sorting matrix

Hello, I would like to sort matrix table by Year and then by value for each Country. How to do it?

Ania26_0-1761217009668.png

Country Year Value
Belarus 2024 19099
Belarus 2025 19023
Belarus 2023 17596
Paraguay 2024 11559
Paraguay 2025 11556
Paraguay 2023 242

1 ACCEPTED SOLUTION

@Ania26 Sorry I just took another look at your picture and now I get what your issue is. You're currently sorting by the Value descending but actually want the dimensions ascending, right?

Your current version probably looks similar to this:

KarinSzilagyi_0-1761325563797.png

 

SortMatrix.gif



Did I answer your question? If so, please consider marking my response as the ‘Accepted Solution’ - it helps others with the same issue find the answer more easily!

View solution in original post

6 REPLIES 6
v-hjannapu
Community Support
Community Support

Hi @Ania26.,

I would also take a moment to thank @Ilgar_Zarbali  , @KarinSzilagyi  for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

Regards,
Community Support Team.

Hi @KarinSzilagyi,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.


Regards,
Community Support team.


Ilgar_Zarbali
Super User
Super User

In Power BI, the Matrix visual allows you to control sorting on multiple levels, but it behaves slightly differently from a normal table.
If you want to sort by Year (in descending order) and then by Value within each Country, follow these steps:

 

Option 1 – Sort using the visual menu

  • Click on the ellipsis (…) in the top-right corner of your Matrix visual.
  • Select Sort by → Year.
  • Then click the ellipsis (…) again and choose Sort by → Value.
    Power BI will apply sorting hierarchically within the Matrix, starting from the outer field (Country → Year → Value).

 

Option 2 – Use a calculated sort column
If the sorting still doesn’t display as expected, create a calculated column in your data model:

 

 

SortOrder =
RANKX(
FILTER(
'Table',
'Table'[Country] = EARLIER('Table'[Country])
),
'Table'[Value],
,
DESC
)

 

Option 3 – Sort the Matrix manually
You can also click directly on the column headers (Year or Value) in the Matrix visual.
Power BI lets you click twice to switch between ascending/descending order for that level.

 

Each Country will appear as a separate group (like Belarus and Paraguay in your screenshot), and inside each group, years will be sorted correctly with the corresponding values.

 

 

I hope it will help you. If so, please give kudoes and accept it as a solution. Thanks

KarinSzilagyi
Solution Sage
Solution Sage

Hi @Ania26, I'd just flip the two fields used in "Rows", so you group first by year, then by country:

KarinSzilagyi_0-1761217569996.png

vs

KarinSzilagyi_1-1761217591593.png

 



Did I answer your question? If so, please consider marking my response as the ‘Accepted Solution’ - it helps others with the same issue find the answer more easily!

Hello, thank you but I want to see first Country and then Year

@Ania26 Sorry I just took another look at your picture and now I get what your issue is. You're currently sorting by the Value descending but actually want the dimensions ascending, right?

Your current version probably looks similar to this:

KarinSzilagyi_0-1761325563797.png

 

SortMatrix.gif



Did I answer your question? If so, please consider marking my response as the ‘Accepted Solution’ - it helps others with the same issue find the answer more easily!

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.