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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
andregrgr
New Member

Power BI Matrix Date Column Sorting

I have a table working for me. Where I have one category in my rows and month-year in my columns. I want to be able to sort my columns by date, soonest to latest but They are sorting alphabetically, the only sorting options I have under more options in the visual are for my columns. 

 

Any help is greatly appreciated. Thank you!

table power bi.png

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @andregrgr 

You need to add a calculated column for sorting order, with the Dax formula :

sort_month_yar = financials[Year]*10000+financials[Month Number]
Ritaf1983_0-1700678530103.png

after this modify the sort order of month year according to this formula from the table view:

Ritaf1983_1-1700678620386.png

result:

Ritaf1983_2-1700678669035.png

Pbix is attached

more information about sorting by another column:

https://www.youtube.com/watch?v=x1tmabi1beA

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

View solution in original post

14 REPLIES 14
Ritaf1983
Super User
Super User

Hi @andregrgr 

You need to add a calculated column for sorting order, with the Dax formula :

sort_month_yar = financials[Year]*10000+financials[Month Number]
Ritaf1983_0-1700678530103.png

after this modify the sort order of month year according to this formula from the table view:

Ritaf1983_1-1700678620386.png

result:

Ritaf1983_2-1700678669035.png

Pbix is attached

more information about sorting by another column:

https://www.youtube.com/watch?v=x1tmabi1beA

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

Hi @Ritaf1983 ,

Thanks for your approach.

What if I need to sort the months in descending order?

Like Jan 2024, Dec 2023, Nov 2023 and so on.

Hi @Nikhil_567 
Then you need a calculated column with this logic to sort by :
sort_month_yar = -(financials[Year]*10000+financials[Month Number])
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Hi @Ritaf1983 , really need your kind assistance, I did what you said my dates are still showing the old year like 2023 and then the new year like 2024 on my Matrix visual, any suggestion as why is that? I have followed all the steps you mentioned by adding the - sign before the measure 

Hi @Mohanad-Mustafa  if it isn't working, something is not as I explained.
Please share the link to the pbix and I will try to help.

 

 

Perfect, worked smoothly!!
Many thanks

Happy to help 🙂

please consider Accepting  the solution to help the other members find it more quickly

@Ritaf1983 In the same visual I need to show months as well (from another date column) on the rows of the matrix, like below-

Nikhil_567_0-1707913025277.png

How can I sort the rows in the same way?

Hi @Nikhil_567 
You can sort the column that is connected to rows on the matrix by the same "order column" that you added. 
There is no limit to how many columns can be ordered by this column.
please consider Accepting  the solution to help the other members find it more quickly

@Ritaf1983 I tried doing the same however getting the error-

Nikhil_567_0-1707915141049.png

 

Hi @Nikhil_567 

This is happening because the dates are likely conflicting with each other's sorting.

Option 1 for a solution:

  • Create an additional column for sorting the second column (less optimal).

Option 2, which is more efficient:

  • Create 2 tables of dates with the required columns, including those intended for sorting.
  • Join them to a fact table.
  • Use one table for rows and the other for columns in the matrix.

please refer to the linked lecture ( from 20 minute).
https://www.youtube.com/watch?v=tBr6IFmmvOE

if you need a guide to creating date tables it is here :

https://radacad.com/power-bi-date-or-calendar-table-best-method-dax-or-power-query

please consider Accepting  the solution to help the other members find it more quickly

worked like a charm. Thanks!

@andregrgr 
You're welcome 🙂

Ritaf1983
Super User
Super User

Hi @andregrgr 

You need to add a calculated column for sorting order, with the Dax formula :

sort_month_yar = financials[Year]*10000+financials[Month Number]
Ritaf1983_0-1700678530103.png

after this modify the sort order of month year according to this formula from the table view:

Ritaf1983_1-1700678620386.png

result:

Ritaf1983_2-1700678669035.png

Pbix is attached

more information about sorting by another column:

https://www.youtube.com/watch?v=x1tmabi1beA

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.