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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
SWhiteMKL
Frequent Visitor

Matrix Sort Help

All,

 

I have a set of data that shows Sales by Group by Year.  I have the matrix arranges wil the row set as Group with Years nested. I have the values as Sales amount.  Here is the requirement.  I need to sort the Group level in descending order by the subtotal and the Years under each group in date order.  I cannot figure out how to mix the sorting to make this happen.  When I sort the Sales in descending order, the Years are out of sequence.  There is a picture of the original structure, the sorted by sales descending and what I actually need to get...

 

Any insights into making this happen is super helpful.

Thanks

Original matrix  Sort desc by Sales  Required sort 
 Gross Sales  Gross Sales  Gross Sales
Group 1600000 Group 2750000 Group 2750000
2020100000 2022400000 2020200000
2021300000 2020200000 2021150000
2022200000>>>2021150000>>>2022400000
Group 2750000 Group 1600000 Group 1600000
2020200000 2021300000 2020100000
2021150000 2022200000 2021300000
2022400000 2020100000 2022200000
Group 3500000 Group 3500000 Group 3500000
2020125000 2022250000 2020125000
2021125000 2020125000 2021125000
2022250000 2021125000 2022250000

 

3 REPLIES 3
SWhiteMKL
Frequent Visitor

I think I understand but when I add the Variable for CurrentGroup the way you suggest the column returns with a circular reference error.  Maybe this is not supported in DirectQuery Mode?

 

Hi @SWhiteMKL,

 

There are limitations/ restrictions when using DirectQuery in Power BI, including limitations to DAX logic, but I am not sure if that is the case here. Could you please share a few more details about the error you are getting, including screenshots, maybe I would be able to help better.

 

Also check out the following blog to learn more about DAX and DirectQuery.

https://blog.crossjoin.co.uk/2017/05/09/dax-functions-directquery-and-unrestricted-measures/

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


Regards,

Bipin Lala | Business Intelligence Developer



Bipin-Lala
Super User
Super User

Hi @SWhiteMKL,

 

I was able to achieve the required sorting in your Matrix Visual, though it was not as forward as expected. This is because Matrix Visual in Power BI does not allow multiple sort columns as the table visual does. You would only be able to sort either by Sales values or by Groups/ Years at a time, as experimented and shown by you as well.

 

To achieve the required sorting shown below, follow the steps - 

BipinLala_1-1714509820141.png

  • Create a calculated column in the sales table to calculate the Group Subtotal for each group. This will help us in sorting the group later. Let's call it Group Sum

 

Group Sum = 
VAR currentGroup = 'Matrix Sort'[Groups]
RETURN CALCULATE(SUM('Matrix Sort'[Sales]), FILTER('Matrix Sort', 'Matrix Sort'[Groups] = currentGroup))​

BipinLala_2-1714510248275.png

 

 

  • You can see the Group SubTotals now using the calculated column. We want to sort the Groups based on this Group Sum. If you try that using the Sort By column functionality, it will throw a circular dependency error.

BipinLala_3-1714510376242.png

  • To avoid this, create a duplicate Groups column that will actually be displayed in the matrix visual. Let's call it Visual Groups

 

Visual Groups = 'Matrix Sort'[Groups]

 

 

  • Sort the Visual Groups column by Group Sum column.

BipinLala_4-1714510510889.png

 

  • Create the matrix visual by adding the fields into current buckets as shown below

BipinLala_5-1714510596440.png

 

  • Sort the Visual Groups Column in descending order by going into visual settings. Remember to select and sort only the Visual Groups field and not the years field, which should get sorted by default

BipinLala_7-1714510744216.png

Voila! It's done. Let me know if you face any issues!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


Regards,

Bipin Lala | Business Intelligence Developer



Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors
Top Kudoed Authors