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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
bernate
Helper II
Helper II

Sorting a Matrix by Color

Hello all! I have a matrix (see below) that is conditionally formatted by a calculated column named "Color." There are 4 colors- red, yellow, green, and blue. I would like to click on a month (column) in the matrix and have the values automatically sort in the order red, yellow, green, blue. If automatic sort is not possible, is there a way to just sort the whole table where each column is sorted by color? 

bernate_0-1726500398162.png

 

I have already created a Sort table and connected it to my Data table on the "Color" column. 

bernate_2-1726500791295.png

1 ACCEPTED SOLUTION

Hi Tom Shen, thank you for your suggestion. I gave up on the matrix for my purposes and instead changed the visual to a table. 

bernate_0-1726605595294.png

 

This allowed me to add a Rank measure that helped me to sort the Sum of Balance. (The Combined Rank Color Measure is in the table and sorted DESC, but minimized)

 

Combined Rank Color =
VAR DateRank =
    RANKX (
        ALL ('Table'[Date]),
        CALCULATE ( SELECTEDVALUE ('Table'[Date]) ),
        ,
        DESC
    )
VAR ColorRank =
    RANKX ( ALL ('Table'[Color]),[Sum Balance])
VAR ColorCount =
    CALCULATE ( DISTINCTCOUNT ('Table'[Color]
]), ALL ('Table') )
VAR HiddenFieldRank =
    RANKX ( ALL ('Table'[HiddenField]),[Sum Balance])
VAR HiddenFieldCount =
    CALCULATE ( DISTINCTCOUNT ('Table'[HiddenField]), ALL ('Table') )
VAR CombinedRank = DateRank
     + ColorRank + HiddenFieldRank
    / (  ColorCount + HiddenFieldCount + 1 )
RETURN
    CombinedRank

View solution in original post

5 REPLIES 5
v-xingshen-msft
Community Support
Community Support

Hi @bernate,
What I tried was to use measure for sorting, if your dataset is huge you can use measure for sorting as measure takes resources only when it is used.

Sort Table(measure) = 
 SWITCH(
    TRUE(),
   MAX( 'Table'[Column])="Red",1,
    MAX('Table'[Column])="Yellow",2,
    MAX('Table'[Column])="Green",3,
    MAX('Table'[Column])="White",4,
   MAX( 'Table'[Column])="Gray",5,
    BLANK()
 )

vxingshenmsft_0-1726559891894.png

 


It is also possible that my dataset is too simple to fully reproduce your problem, if you can provide your example data or pbix file, it will help you solve the problem faster, I look forward to your reply, I will get back to you as soon as I receive your message!

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

 

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

Hi Tom Shen, thank you for your suggestion. I gave up on the matrix for my purposes and instead changed the visual to a table. 

bernate_0-1726605595294.png

 

This allowed me to add a Rank measure that helped me to sort the Sum of Balance. (The Combined Rank Color Measure is in the table and sorted DESC, but minimized)

 

Combined Rank Color =
VAR DateRank =
    RANKX (
        ALL ('Table'[Date]),
        CALCULATE ( SELECTEDVALUE ('Table'[Date]) ),
        ,
        DESC
    )
VAR ColorRank =
    RANKX ( ALL ('Table'[Color]),[Sum Balance])
VAR ColorCount =
    CALCULATE ( DISTINCTCOUNT ('Table'[Color]
]), ALL ('Table') )
VAR HiddenFieldRank =
    RANKX ( ALL ('Table'[HiddenField]),[Sum Balance])
VAR HiddenFieldCount =
    CALCULATE ( DISTINCTCOUNT ('Table'[HiddenField]), ALL ('Table') )
VAR CombinedRank = DateRank
     + ColorRank + HiddenFieldRank
    / (  ColorCount + HiddenFieldCount + 1 )
RETURN
    CombinedRank

Hi @bernate ,

Thanks for the feedback, it's great to see that you've found a solution! If you have any other questions or need From the current situation, you have found the corresponding solution situation, if you can, please mark your answer as solved to help other users encountering similar problems, if you have further questions, feel free to contact me, I will reply to you as soon as I receive the message!

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

 

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

dharmendars007
Memorable Member
Memorable Member

Hello @bernate , 

 

Please make sure you have sorted the "Color" column in your main data table by "Sort Order" column.

 

If you find this helpful , please mark it as solution and Your Kudos are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

Hi Dharmendar, yes I do. Here is the result when I apply a sort to the matrix.

bernate_2-1726501867334.png

 

As you can see, the sorting doesn't seem to be in any order.

bernate_3-1726502173152.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.