This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
I have a matrix where I need to sort the rows in a specific order. How can I do this?
Solved! Go to Solution.
Hi @Dawg ,
In Power BI, you can control the row sorting in a matrix by creating a custom column that defines the desired order. If your categories or row labels need to follow a specific sequence, you can add a numeric column that assigns a sort order to each value. For example, you can create a calculated column using DAX:
SortOrder = SWITCH(
'Table'[Category],
"Category A", 1,
"Category B", 2,
"Category C", 3,
"Category D", 4,
99 // Default case
)
Once this column is created, select the original column in the Data View, go to Column Tools, and choose Sort by Column, then select the SortOrder column. This ensures that Power BI follows the defined sequence instead of sorting alphabetically. If your dataset is coming from Power Query, you can achieve the same effect by adding an Index Column that assigns a numeric order to your rows. Then, use the Sort by Column feature to sort the rows in the desired order.
If sorting needs to be dynamic based on a measure, you may encounter limitations in sorting directly within the matrix. In such cases, you can create a ranking measure using RANKX and sort by that measure:
RankMeasure = RANKX(ALL('Table'[Category]), [YourMeasure], , ASC, DENSE)
If Power BI does not allow sorting directly by a measure, you may need to apply additional transformations in Power Query or use calculated columns to enable sorting. Let me know if your sorting scenario is more complex!
Best regards,
HI @Dawg,
Perhaps you can check the following blog about the custom sorting on table/matrix if this help for your scenario:
Regards,
Xiaoxin Sheng
HI @Dawg,
Perhaps you can check the following blog about the custom sorting on table/matrix if this help for your scenario:
Regards,
Xiaoxin Sheng
Hi @Dawg ,
In Power BI, you can control the row sorting in a matrix by creating a custom column that defines the desired order. If your categories or row labels need to follow a specific sequence, you can add a numeric column that assigns a sort order to each value. For example, you can create a calculated column using DAX:
SortOrder = SWITCH(
'Table'[Category],
"Category A", 1,
"Category B", 2,
"Category C", 3,
"Category D", 4,
99 // Default case
)
Once this column is created, select the original column in the Data View, go to Column Tools, and choose Sort by Column, then select the SortOrder column. This ensures that Power BI follows the defined sequence instead of sorting alphabetically. If your dataset is coming from Power Query, you can achieve the same effect by adding an Index Column that assigns a numeric order to your rows. Then, use the Sort by Column feature to sort the rows in the desired order.
If sorting needs to be dynamic based on a measure, you may encounter limitations in sorting directly within the matrix. In such cases, you can create a ranking measure using RANKX and sort by that measure:
RankMeasure = RANKX(ALL('Table'[Category]), [YourMeasure], , ASC, DENSE)
If Power BI does not allow sorting directly by a measure, you may need to apply additional transformations in Power Query or use calculated columns to enable sorting. Let me know if your sorting scenario is more complex!
Best regards,
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 28 | |
| 23 | |
| 22 | |
| 16 | |
| 16 |
| User | Count |
|---|---|
| 61 | |
| 35 | |
| 28 | |
| 22 | |
| 22 |