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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
SteveCS
Frequent Visitor

Sorting Matrix with a field not in the matrix visual

How do you sort a matrix using a column that's not physically in the matrix visual?

Here's the visual

SteveCS_2-1740493469664.png


The column and values are aging # (how many records are 1 day old, two days old, etc.
The week referred is a text field, based off of a date field (each date falls into the week_referred bucket).

When I try to sort that field, it isn't sorting accurately. I want it to sort by the latest bucket on top in descending order.  But the date that it's based on is not in the matrix.

The data in this table is a SQL Server table using t-sql to sort the data and it's sorting properly at the table level. But not when I put the fields in the matrix.

I'm sure this comes up quite often but can't find the solutions that I need.|
Help is appreciated.

Thanks, Steve.

SteveCS_0-1740493196471.png

 

2 REPLIES 2
v-yaningy-msft
Community Support
Community Support

Hi, @SteveCS 

Thanks for the reply from @freginier. You can refer to his reply, here is more information about field sorting.
Sort one column by another column in Power BI - Power BI | Microsoft Learn

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

freginier
Solution Sage
Solution Sage

Hey there!

 

Since you want to sort the "Week_Referred" field based on a hidden date field, but the date itself is not in the matrix, follow these steps to fix sorting issues.

 

Since Week_Referred is a text field, Power BI sorts it alphabetically instead of by date order.
To solve this, ensure there is a numeric or date-based column that represents the week start date.

If you don't have this column, create a Week Start Date column: Week_Start_Date = MIN('Table'[Date])

 

Once you have a numeric or date column, sort the text column by it:

- Go to Data View (Table View in Power BI).
- Select the "Week_Referred" column.
- Click Column Tools > Sort by Column and choose Week_Start_Date (or another numeric date column).
This tells Power BI to sort Week_Referred based on actual week order instead of text order.

 

Now:

Go back to your Matrix visual. Click the Week_Referred column header and sort in descending order (latest first).

 

If sorting is still incorrect, create a numeric index for each week: Week_Sort_Index = RANKX(ALL('Table'), MIN('Table'[Week_Start_Date]), , ASC, DENSE)

- Then, in Step 2, sort "Week_Referred" by "Week_Sort_Index".

 

With all this done, "Week_Referred" will be sorted by actual week order (oldest → latest or latest → oldest).
You don't have to display the date column, but sorting will still work.

 

Hope this helps!

😁😁

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors