Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Sorting DAX date table

I currently have a date table I use for my table matrix.  Im trying to show 2020 and 2021 data in the matrix, but want it sorted desending showing jan 4 2021 first and going down.  I cant seem to get it that way since I have 3 date columns in the matrix Year, Month and day.  No matter waht way I sort I cannot get it this way. I tired sorting by all of the 3, but doesnt work since the year is the top.  Only works when Im doing 1 month. 

 

Thanks

10 Replies

  • vanessafvg's avatar
    vanessafvg
    Community Champion

     why dont you create a date column from the 3 columns?  

  • Anonymous , Where are you showing date , If you showing on column(pivot) you need to have sort column to change it to descending.

     

    Create date if you do not have

    Date = date([Year],[month], [day])

    Date1 = date([Year],[month], [day])

    Date Sort = rankx(all(Table), [Date],,desc)

     

    Sort Date1 on date sort and use.

    Refer to my video on this: https://www.youtube.com/watch?v=KK1zu4MBb-c

    • Anonymous's avatar
      Anonymous
      Not applicable

      Its in a MAtrix table

      • ASK15's avatar
        ASK15
        Frequent Visitor

        i have been facing same problem .year sorting with follow the month sequnce

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

    Have you tried to create a calculated table with custom sorting orders and link to your raw table fields?

    Custom Sorting in Power BI 

    BTW, for multiple column sorting, you can try to use ISONORAFTER function:

    Sorting by multiple columns 
    Regards,

    Xiaoxin Sheng

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous.,

    Did these suggestions help with your requirement? If not, please provide more detailed information and some dummy data to help us clarify your scenario and test to coding formula.

    How to Get Your Question Answered Quickly 

    Regards.

    Xiaoxin Sheng

  • Anonymous's avatar
    Anonymous
    Not applicable

    Sorry I have been OOO.  I was able to just use the main date and sort it that way instead of by month, day , year

    • Anonymous's avatar
      Anonymous
      Not applicable

      HI Anonymous,

      I'm not so clear about your descriptions, can you please share some dummy data with the expected result (the way similar as the above blog link mention) to help us clarify your scenario and requirements?

      BTW, if you are working with situations that similar as creating 'sorting order' on a calendar based on fiscal date, you can take a look at the following blog:

      DAX 101: Sorting months in fiscal calendars 

      Regards,

      Xiaoxin Sheng