Forum Discussion

andregrgr's avatar
andregrgr
New Member
2 years ago
Solved

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, ...
  • Ritaf1983's avatar
    2 years ago

    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]

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

    result:

    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

  • Ritaf1983's avatar
    2 years ago

    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]

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

    result:

    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

  • Ritaf1983's avatar
    Ritaf1983
    2 years ago

    Hi Anonymous 
    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

  • Ritaf1983's avatar
    Ritaf1983
    2 years ago

    Hi Anonymous 
    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's avatar
    Ritaf1983
    2 years ago

    Hi Anonymous 

    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

  • Ritaf1983's avatar
    Ritaf1983
    2 years ago

    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.