Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi,
I was wondering if it was possible to sort a column based on two columns?
In the example below I'm trying to sort the Category by the Sort_Order column. The problem is that the sort order is different for the same values within each group. Ideally what I'm looking for is to sort the category by the Sort_Order within each group. Is this possible?
| Group | Category | Sort_Order |
| 1 | Large | 1 |
| 1 | Small | 2 |
| 1 | Medium | 3 |
| 2 | Small | 1 |
| 2 | Medium | 2 |
| 2 | Large | 3 |
I appreciate any help with.
Many thanks,
Ash
Solved! Go to Solution.
Hi @aburling1989 ,
You could create a rank column to sort category.
Rank =
RANKX ( 'Table', 'Table'[Group] * 10 + 'Table'[Sort_Order],, ASC, DENSE )
Hi @aburling1989 ,
You could create a rank column to sort category.
Rank =
RANKX ( 'Table', 'Table'[Group] * 10 + 'Table'[Sort_Order],, ASC, DENSE )
also, you can check here https://www.c-sharpcorner.com/article/how-to-sort-a-table-using-multiple-columns-in-power-bi/ to understand how to sort Table visual by a multiple columns (hint: use Shift + Click)
If I understand you correct you can create a Surrogate Order Column and try to sort by it, like
Surrogate Order Column =
CONCATENATE(Table[Group], CONCATENATE("_", Table[Sort_Order]) )
Hi @az38 ,
Many thanks for the quick response. The problem is the values in the 'Category' column are not unique, so even if I concatenate the 'Group' and 'Sort' columns I still get this error message: "There can't be more than one value in 'Category' for the same value in 'Surrogate Order Column'.
If I concatenate the 'Group' and 'Category' column it would work as they become unique values but I want to avoid doing that if possible.
Many thanks,
Ashley
Do you create measure or column?
If column, there shouldn't be such error
Hi @az38 ,
I added it as a column and it certainly sorts the data correctly; However the issue I still have is that I can't specifically sort the 'Category' by this column. So if I was to add 'Category' to a slicer it still defaults the sort order alphabetically, but I would want it sorted by the new 'Surrogate Order Column'.
Thanks again for your help.
Ashley
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 57 | |
| 37 | |
| 34 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 74 | |
| 70 | |
| 37 | |
| 35 | |
| 25 |