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! Learn more

Reply
DatamirHub
Helper I
Helper I

Sort Matrix Columns by Values

I have this matrix view

DatamirHub_0-1756456536610.pngDatamirHub_1-1756456829142.png

 

I want my users to have the ability to sort by any column they want (e.g. rev of 2024 or 2023, or cap of 2024, ... etc)

I cant click on the columns to sort
when i go to the 3 dots on top right and sort by that i have only the ability to sort by the metrics which always sort by the last year values not a specific year value

is there a workaround to this I know some articles mentioned that not possible in Power BI

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @DatamirHub ,

 

I have create a work around based on some slicers and a calculation group but this can depend on the way you have your semantic model.

 

In my case I have the following table:

MFelix_0-1756459578157.png

 

Add the following measures:

Cap Value = SUM('Data Values'[cap])

Rev Value = SUM('Data Values'[rev])

I have also created the following two disconnected tables:

MFelix_1-1756459638118.pngMFelix_2-1756459650042.png

 

 

Then I created a calculation group with the following code:

Calculation item =
VAR _measure =
    SELECTEDVALUE ( 'Measures filter'[Measure] )
VAR _year =
    SELECTEDVALUE ( 'Year filter'[year] )
VAR _temptable =
    CALCULATETABLE (
        ADDCOLUMNS (
            'Data Values',
            "valuetotal", SWITCH ( _measure, "cap", [Cap Value], "rev", [Rev Value] )
        ),
        'Data Values'[year] = _year
    )
RETURN
    IF (
        NOT ( ISINSCOPE ( 'Data Values'[year] ) ),
        SUMX ( _temptable, [valuetotal] ),
        SELECTEDMEASURE ()
    )

 

Now if you add the measures to your values and apply the calculation group you get the following result:

MFelix_3-1756459795447.png

 

Has you can see the totals have in this case the values for the rev value 2023, if I changed it to 2024 it gets the inverse order because I'm doing the order by total:

 

MFelix_4-1756459876445.png

 

It does not matter wich of the column of the total you select because they will be equal.

 

Then you can hide the totals column and it continues to sort in the same way:

 

MFelix_5-1756459977619.png

Only question that I did not address here was the highest to lowest or lowest to highest not sure if you want it.

See pbix file attach.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

6 REPLIES 6
MFelix
Super User
Super User

Hi @DatamirHub ,

 

I have create a work around based on some slicers and a calculation group but this can depend on the way you have your semantic model.

 

In my case I have the following table:

MFelix_0-1756459578157.png

 

Add the following measures:

Cap Value = SUM('Data Values'[cap])

Rev Value = SUM('Data Values'[rev])

I have also created the following two disconnected tables:

MFelix_1-1756459638118.pngMFelix_2-1756459650042.png

 

 

Then I created a calculation group with the following code:

Calculation item =
VAR _measure =
    SELECTEDVALUE ( 'Measures filter'[Measure] )
VAR _year =
    SELECTEDVALUE ( 'Year filter'[year] )
VAR _temptable =
    CALCULATETABLE (
        ADDCOLUMNS (
            'Data Values',
            "valuetotal", SWITCH ( _measure, "cap", [Cap Value], "rev", [Rev Value] )
        ),
        'Data Values'[year] = _year
    )
RETURN
    IF (
        NOT ( ISINSCOPE ( 'Data Values'[year] ) ),
        SUMX ( _temptable, [valuetotal] ),
        SELECTEDMEASURE ()
    )

 

Now if you add the measures to your values and apply the calculation group you get the following result:

MFelix_3-1756459795447.png

 

Has you can see the totals have in this case the values for the rev value 2023, if I changed it to 2024 it gets the inverse order because I'm doing the order by total:

 

MFelix_4-1756459876445.png

 

It does not matter wich of the column of the total you select because they will be equal.

 

Then you can hide the totals column and it continues to sort in the same way:

 

MFelix_5-1756459977619.png

Only question that I did not address here was the highest to lowest or lowest to highest not sure if you want it.

See pbix file attach.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks, @MFelix this is interesting I will try it out if it works as expected, I will reach out to get an idea of how to do the highest to lowest or lowest to highest

Hi @DatamirHub ,

 

For the highest to lowest add the following table:

MFelix_0-1756473406990.png

 

Now updated the calculation group to:

Calculation item = 
VAR _measure =
    SELECTEDVALUE ( 'Measures filter'[Measure] )
VAR _year =
    SELECTEDVALUE ( 'Year filter'[year] )
VAR _sorting =
    SELECTEDVALUE('Sorting Order'[Sort])

VAR _temptable =
    CALCULATETABLE (
        ADDCOLUMNS (
            'Data Values',
            "valuetotal", SWITCH ( _measure, "cap", [Cap Value], "rev", [Rev Value] )
        ),
        'Data Values'[year] = _year
    )
RETURN
    IF (
        NOT ( ISINSCOPE ( 'Data Values'[year] ) ),
        SUMX ( _temptable, [valuetotal] )  * _sorting,
        SELECTEDMEASURE ()
    ) 

Now the total column will be properly sorted:

MFelix_1-1756473473417.png

 

MFelix_2-1756473489559.png

 

MFelix_3-1756473512121.png

 

 

See PBIX file attach.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



DatamirHub
Helper I
Helper I

Hey @Shahid12523 and @rohit1991 Thank you both for the workarounds

Unfortunatelly I have to stick with a matrix and i cant add a year filter because I already have two field parameters table one for the year and one for the measures
and the year filter can have multiple years but we want only to sort by specific year 

Thanks !

Shahid12523
Community Champion
Community Champion

Power BI Matrix visuals don’t support sorting by individual columns like “Rev 2024” directly. But here’s a quick workaround:
Use a slicer to let users choose which year/category to sort by.
Create a dynamic measure that changes based on slicer selection.
Sort your rows using that measure (via RANKX or hidden column).
Direct column-click sorting isn’t possible—only Table visuals support that.

Shahed Shaikh
rohit1991
Super User
Super User

Hi @DatamirHub 

Could you please try below steps:

  • Unpivot your data in Power Query so that “Year” and “Measure (Rev/CAP)” become rows instead of columns. Then you can build a table visual and users will be able to click and sort by any Year/Measure combination.
  • Or, create a separate table visual for each Year if column-level sorting is critical.
  • If the requirement is interactive sorting, another option is to build a field parameter or a slicer that lets the user choose which Year/Metric they want to sort by, and then apply that dynamically to the Matrix/Table.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

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