Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Sana-Shaikh
Frequent Visitor

Matrix Sorting

Hello,

I have a table that has columns Dept Names, Employees and hours worked. I created a matrix that shows Dept Names and Employees as rows and hours worked as a column. I want to sort the total hours worked for each dept in DESC order, simutaneously, I want to sort the Employee IDs in ASC order regardless of how many hours they worked. I am trying to create a calculated column to concatenate but am having trouble figuring out what I am doing wrong. 

Is there anyone who can help me with this?

9 REPLIES 9
Ritaf1983
Super User
Super User

Hi @Sana-Shaikh 

please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

@Ritaf1983 

SanaShaikh_0-1726247532003.png

Sorry about that. So this would eb an example of the visual I currently have. I have it sorted DESC by Hours worked. For the matrix I want, teh hours to be the same as they are now, in descending order, but the Employee IDs need to be rearraged to be in ascending order such as:

SanaShaikh_1-1726247766747.png

So the Total/Sum of the Hours worked is Desc order, while the Employee ID's under the department umbrella is in Asc order. Is there a DAX column that can achieve these results?

Hi @Sana-Shaikh 
If I understood you correctly you trying to achieve a different sort of order by hierarchies.
Take a look at the workaround in the linked blog post + linked discussion :
https://stuffbyyuki.com/hierarchical-sorting-in-power-bi/

https://community.fabric.microsoft.com/t5/Desktop/PowerBi-hierarchy-sort-multiple-levels/td-p/276394...

 

If my answer was helpful please give me a Kudos and accept as a Solution.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

@Ritaf1983 ,
I don't want to create a new column for sort. 

SanaShaikh_0-1726257448739.png

The values don't match what I would want. The Total values that are bolded would be in descending order: 5500, 2800, 1500, 1500 for this 
The subgroups would be ordered Small, Medium, Big for each Product Category 

Hi, @Sana-Shaikh  to sort different levels by different "order types" you still need to add something that will manage the wanted order because we don't have this functionality as an option for the visuals.
If you need it dynamic it must be a column of your matrix. 

Ritaf1983_0-1726285825121.pngRitaf1983_1-1726285885648.png

After sorting you can minimize the sort manager column width to "hide" it and leave just a sort rectangle

Ritaf1983_2-1726286872214.png

To create this logic you need :
1. To have a sort column for the IDs with the numeric value like :

Ritaf1983_3-1726287244772.png

 

 



2. Sort sub-categories by this column from the table view

Ritaf1983_4-1726287579503.png

 

3. Create a sort manager measure:

sort rank =
var rank_value= RANKX(ALLSELECTED('Table'[Category]),[Sum_],,DESC)
Return
If(ISINSCOPE('Table'[Sub category]),max('Table'[Sort manager]),rank_value)
Ritaf1983_5-1726287723371.png

 

4. Sort by this column :

Ritaf1983_6-1726287826322.png

5. To Hide the column but leave the rectangle visible for users :
Rename it on visual :

Ritaf1983_7-1726288033439.png

format column values and totals as a white color :

Ritaf1983_8-1726288187612.png

Result :

Ritaf1983_9-1726288214495.pngRitaf1983_10-1726288239889.png

PBIX is Attached

If my answer was helpful please give me a Kudos and accept as a Solution.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

@Ritaf1983 
Let's try this from a different approach. When I create the matrix, the system already puts the sub group (Employee ID's) in ASC order. Now what I would like to do is instead of doing Sort by Column for hours(which is a column value), I want to create a calculated column or measure that will sort the Total Hours by department in DESC order

Let's just use the image you gave by example

SanaShaikh_0-1726503843604.png

The Sum per group is in desc order. the subgroups are in asc order. Without using Sort by Column, an this be achieved?

Hi @Sana-Shaikh 
No.

If my answer was helpful please give me a Kudos and accept as a Solution.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

@Ritaf1983 ,

I understand how to do a sort column, I want to know if there is a way to accomplish this without a sort column, maybe with a concatenation? In case Employee Id's change.

Hi @Sana-Shaikh 
I don't think that there is another dynamic alternative to this issue.

If my answer was helpful please give me a Kudos and accept as a Solution.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Top Kudoed Authors