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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
a68tbird
Resolver II
Resolver II

Matrix Sort by Column Header Date Descending

This is a popular topic on the boards, I know, and I've read many different solutions, however nothing seems to be working for me and it's got me stumped.

 

My matrix has a Date Hierachy for columns.  It's 8 years of columns, so I'd like the most recent year leftmost in the table.  I added a RANK() line to my SQL query:

RANK() over(order by Skus.EventDate DESC) as DateSort

 which gives the most recent date a value of 1, and so on.  Based on this column I then used the Sort By Column (sort EventDate by DateSort).  It all looks fine in the Data view (although - is there supposed to be a check mark beside the column selected as the sort by? Mine doesn't show a checkmark....)

a68tbird_0-1644517786463.png

 

Going back to look at my matrix, it hasn't done anything - old year is still leftmost.  What am I missing? 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @a68tbird ;

I tested it , product as rows, sales as values, date as  column;

vyalanwumsft_0-1644908134988.png

If the column is Date Hierarchy, sort by column is not work ,so we should change the different column about year and month.

create a rank column.

Column =RANKX('financials',YEAR('financials'[Date]),,DESC,Dense)

vyalanwumsft_1-1644908790938.png

 

The final output is shown below:

vyalanwumsft_2-1644908852118.png

vyalanwumsft_3-1644908887525.pngvyalanwumsft_4-1644908925448.png

 


Best Regards,
Community Support Team_ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @a68tbird ;

I tested it , product as rows, sales as values, date as  column;

vyalanwumsft_0-1644908134988.png

If the column is Date Hierarchy, sort by column is not work ,so we should change the different column about year and month.

create a rank column.

Column =RANKX('financials',YEAR('financials'[Date]),,DESC,Dense)

vyalanwumsft_1-1644908790938.png

 

The final output is shown below:

vyalanwumsft_2-1644908852118.png

vyalanwumsft_3-1644908887525.pngvyalanwumsft_4-1644908925448.png

 


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

a68tbird
Resolver II
Resolver II

Everything that I'm reading, seems to suggest that this should work.  I decided to create a brand new report, new sample data, and try it again from scratch.  With my data imported, I created two calculated columns:

 

DateSort = sampleData[RecognitionDate].[Date]
Rank = RANKX(sampleData,sampleData[RecognitionDate],,,Skip)

 

I then sorted the DateSort date by Rank.  This displays correctly in the Data view (most recent sales date is ranked 1).  I then add three fields to a matrix: Products as Row, StoreTotal as Value and DateSort as Columns.  The matrix still has oldest year leftmost in the grid.  

I've followed a suggestion from this post: Solved: Sort date field in Matrix column header descending - Microsoft Power BI Community but it's not working for me.  Does the fact that I'm using a Date Hierachy in the matrix make a difference?  

parry2k
Super User
Super User

@a68tbird no, it doesn't show the checkmark but highlights the sorted by column and in your case, it looks ok.

 

Can you click on the top right corner 3 dots on the matrix visual and make sure the correct column is used for sorting.

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

EventDate doesn't show as an option there in the Sort By.  I thought that was the whole issue with the "sort by column headers".  By default PowerBI sorts the date by ASC, and columns don't appear in the matrix visual sort by options. 

 

a68tbird_0-1644527007851.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.