Forum Discussion
Sorting by the last column
Hello,
CountryValueYear
| USA | 1 | 2023 |
| France | 3 | 2023 |
| Canada | 1 | 2023 |
| USA | 2 | 2024 |
| France | 1 | 2024 |
| Canada | 6 | 2024 |
For the data above , I have amtrix table:
How can I sort by the last column? 2024. descending?
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 column β Sort Descending.
- If the sort is incorrect, adjust sorting in Visual Level Filters:
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!
ππ
6 Replies
- freginierSolution Sage
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 column β Sort Descending.
- If the sort is incorrect, adjust sorting in Visual Level Filters:
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!
ππ
- Ania26Helper IV
Hello, Thank you for this but this will not work when someone will filter other than 2024 year.
- v-echaithraCommunity 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. - v-echaithraCommunity 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-echaithraCommunity 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-echaithraCommunity 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.