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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
DVannurVali
Frequent Visitor

Assistance Needed with Sorting in Matrix Visual.

Hello Everyone,

I hope you're all doing well!

I’m currently working with a Matrix visual where:

  • Rows contain Channel

  • Columns contain Month & Year

  • Values include a Single Measure that dynamically represents all of the following:
    #Stores, Contr., LY, YTD, QTD, Mar-25, Apr-25, May-25, Jun-25, Vs LM, % Vs LM, % Vs LY, % Vs YTD

 

Please refer to the snapshot below for clarity.

 

DVannurVali_0-1749616347374.png

Requirement:

I need to sort the matrix based on #Stores in descending order (highest to lowest).

Here’s the expected output format for reference.


DVannurVali_1-1749616428174.png

Note:

To meet the business requirements, all measures have been combined into a single dynamic measure. Below is the DAX measure used in the matrix visual:

 

Measure Used in Matrix Visual =
VAR SelectedDate = SELECTEDVALUE('Dim_Calendar'[Date], MAX('Dim_Calendar'[Date]))
VAR Selection = SELECTEDVALUE('Sales Dynamic Measure Table'[Month & Year])

-- Pre-calculate values
VAR StoreCount = [# Stores]
VAR SalesContr = [% Channel Sales Contribution]
VAR SalesLY = [Sales AMT SLY]
VAR SalesYTD = [Sales YTD]
VAR SalesQTD = [Sales QTD]
VAR CMSales = [CM Sales]
VAR LMSales = [LM Sales]
VAR Sales2M = [Last 2M Sales]
VAR Sales3M = [Last 3M Sales]
VAR SalesVsLM = [Sales Vs LM]
VAR SalesPctVsLM = [Sales % Vs LM]
VAR SalesPctVsLY = [SLY % Sales]
VAR SalesPctVsYTD = [SLY % Sales YTD]

-- Format reference months
VAR M0 = FORMAT(EOMONTH(SelectedDate, 0), "Mmm-YY")
VAR M1 = FORMAT(EOMONTH(SelectedDate, -1), "Mmm-YY")
VAR M2 = FORMAT(EOMONTH(SelectedDate, -2), "Mmm-YY")
VAR M3 = FORMAT(EOMONTH(SelectedDate, -3), "Mmm-YY")

-- Raw result logic
VAR RawValue =
SWITCH(TRUE(),
Selection = "#Stores", StoreCount,
Selection = "Contr.", SalesContr,
Selection = "LY", DIVIDE(SalesLY, 1000),
Selection = "YTD", DIVIDE(SalesYTD, 1000),
Selection = "QTD", DIVIDE(SalesQTD, 1000),
Selection = M0, DIVIDE(CMSales, 1000),
Selection = M1, DIVIDE(LMSales, 1000),
Selection = M2, DIVIDE(Sales2M, 1000),
Selection = M3, DIVIDE(Sales3M, 1000),
Selection = "Vs LM", DIVIDE(SalesVsLM, 1000),
Selection = "% Vs LM", SalesPctVsLM,
Selection = "% Vs LY", SalesPctVsLY,
Selection = "% Vs YTD", SalesPctVsYTD,
BLANK()
)

-- Final formatted result
RETURN
SWITCH(TRUE(),
ISBLANK(RawValue), BLANK(),

-- Percentages
Selection IN { "Contr.", "% Vs LM", "% Vs LY", "% Vs YTD" },
FORMAT(RawValue, "0%"),

-- Store count: whole number with comma
Selection = "#Stores",
FORMAT(RawValue, "#,0"),

-- Thousand-separated "K" format for selected items
Selection IN { "LY", "YTD", "QTD", "Vs LM", M0, M1, M2, M3 },
FORMAT(RawValue * 1000, "#,0,K"),

-- Fallback
FORMAT(RawValue, "0")
)

Looking forward to your suggestions and support on how to implement sorting based on #Stores in this setup.

Thanks for your time and assistance!

Best regards,
D. Vannur Vali

 

5 REPLIES 5
v-hashadapu
Community Support
Community Support

Hi @DVannurVali , I hope you're doing well! Just checking in to see if you had a chance to review the details shared earlier. If any of the information addressed your needs, feel free to mark it as "Accept as Solution"  to help others in the community. Please let me know if you have any further questions!

v-hashadapu
Community Support
Community Support

Hi @DVannurVali , I wanted to check with you and see if the provided information was useful. If any of it helped resolve your question, consider marking it as "Accept as Solution" to make it easier for others to find. Let me know if there's anything else I can assist with!

Ritaf1983
Super User
Super User

Hi @DVannurVali 

Please relate to my solution in the linked post.

https://community.fabric.microsoft.com/t5/Desktop/How-to-sort-columns-in-a-matrix-by-measure-value/m...

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

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

Hi @Ritaf1983, Thank you for the quick response.


I’ve reviewed the details you shared, but it seems the solution doesn’t quite align with my specific scenario.


I appreciate your time and support.

Hi @DVannurVali 

It actually is —
There’s no option in a regular Matrix to sort rows by a specific column.
At the same time, you're required to use the “Columns” bucket, and you can’t apply a different sort order for each column, due to the special structure you’ve created.
That’s why it’s not possible to solve this within the standard Matrix visual.
The Matrix from the Marketplace mentioned in the post does allow sorting by individual columns —
which is exactly why the solution I referred you to is suitable for your case.

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

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

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.