Forum Discussion

Cathryn's avatar
Cathryn
Helper III
6 years ago
Solved

Date table - can't sort other columns by date Getting error

Hi All

 

I am so stuck on this.  I created a date table with the code below but when I try to sort the Month column by the date so my dates show up in the correct order in charts, I get the error:

 

"We can't sort the 'Month' column by 'Date'.  There can't be more than one value in 'Date' for the same value in 'Month'.  Please choose a different column for sorting or update the data in 'Date'"

 

All the dates are unique so I can't figure out what else to do.

 

Calendar = var _caledndar = calendar("1/1/2019","12/31/2025") return ADDCOLUMNS(_calendar, "Year", YEAR([Date]), "MonthNumber", MONTH([Date]), "Month", FORMAT([Date], "mmm"))
 
The calendar code was copied from "Guy in a Cube"
 
How else can I sort the date table?
 
Cathryn

 

 

  • dax's avatar
    dax
    6 years ago

    Hi Cathryn , 

    Did you want to get result like below?

    If so, you could set "sort by " on Month like below

    Best Regards,
    Zoe Zhi

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

     

4 Replies

  • Cathryn you should sort Month column by Month Number instead of date column

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    • Cathryn's avatar
      Cathryn
      Helper III

      Thank you.  I tried your suggestion and it didn't work when I tried to then sort in my charts by year and then month.  

       

      But, I recreated the calendar table in a previous version of my pbix file and it created the date hierarchy for me and using that, it showed the months and years in order.

       

      Thank you so much for your quick response.

       

      Cathryn

      • dax's avatar
        dax
        Community Support

        Hi Cathryn , 

        Did you want to get result like below?

        If so, you could set "sort by " on Month like below

        Best Regards,
        Zoe Zhi

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