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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
sirgeli
Regular Visitor

how to sort a matrix in powerbi by a specific column

Hi, how can one get a matrix in powerBI to sort on a specific column?

I want to sort on the latest quarter's rank, the quarter will change over time, so cannot hard code it.

sirgeli_0-1733828371207.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @sirgeli 

Based on your information, I create a sample table:

vyohuamsft_0-1734426565708.png

vyohuamsft_2-1734426974993.png

 

Then create a new measure

 

LatestQuarterRank = 
VAR LatestQuarter = MAX('DateTable'[Quarter])
RETURN
RANKX(
    ALL('Table'[Category]),
    CALCULATE(
        SUM('Table'[Value]),
        'DateTable'[Quarter] = LatestQuarter
    ),
    ,
    DESC,
    DENSE
)

 

 Add the LatestQuarterRank metric to the matrix visualization. Sort the matrix by measure:

vyohuamsft_3-1734427029972.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi, @sirgeli 

Based on your information, I create a sample table:

vyohuamsft_0-1734426565708.png

vyohuamsft_2-1734426974993.png

 

Then create a new measure

 

LatestQuarterRank = 
VAR LatestQuarter = MAX('DateTable'[Quarter])
RETURN
RANKX(
    ALL('Table'[Category]),
    CALCULATE(
        SUM('Table'[Value]),
        'DateTable'[Quarter] = LatestQuarter
    ),
    ,
    DESC,
    DENSE
)

 

 Add the LatestQuarterRank metric to the matrix visualization. Sort the matrix by measure:

vyohuamsft_3-1734427029972.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

danextian
Super User
Super User

Hi @sirgeli 

The sorting using a measure is based on the total of those columns. So you need to write a measure that returns the latest quarter's rank at the total. For example,

IF(
    NOT(HASONEVALUE('datetable'[quarter])),
    [latest quarter rank],
    [per quarter rank]
)

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Below is a sample formula

Latest Quarter Rank =
VAR LatestQuarter =
     --to calculate the latest quarter with value
    CALCULATE ( LASTNONBLANK ( Dates[Quarter], [Total Revenue] ), ALL ( Dates ) )
RETURN
    RANKX (
        --column to rank
        ALL ( Data[Geo] ),
        CALCULATE (
            [Total Revenue],
            FILTER ( ALL ( Dates ), Dates[Quarter] = LatestQuarter )
        ),
        ,
        DESC,
        DENSE
    )




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

sorry, I am very new to this and I think I am doing something wrong, I tried your suggestion, but are getting a bunch of 1's in the rank column and it applies it to all quarters in the table:

sirgeli_0-1733907081031.png

my measure:

Latest Quarter Rank =
VAR LatestQuarter =
     
    CALCULATE ( LASTNONBLANK ( 'ASISA Stats'[Date], [Total AUM] ), ALL ( 'ASISA Stats'[Date] ) )
RETURN
    RANKX (
      
        ALL ( 'ASISA Stats'[AUM] ),
        CALCULATE (
            [Total AUM],
            FILTER ( ALL ( 'ASISA Stats'[Date] ), 'ASISA Stats'[Date] = LatestQuarter )
        ),
        ,
        DESC,
        DENSE
    )

how would I create a measure for latest quarter rank and per quarter rank?

Want to try your solution, but not 100% sure what to do for those two parameters?

Uzi2019
Super User
Super User

Hi @sirgeli 

 

You can simply sort the matrix table by using sort by fucntionality. follow the screenshot for your guidline.

 

Uzi2019_0-1733830011455.png

 

 

I hope I answered your question!

 

Let me know if I am missing something

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

that doesn't work, else I would have done that, it actually sorts it by the total column and not the Sep 2024 rank column

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.