Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Issue converting date to MMM-YY

I have a date column which I want to convert to MMM-YY format. I used this formula: 

 

= left(format(month([Date]),"mmmm"),3) & "-" & right(Year([Date]),2)
 
But for some reason, all the columns that are  January 2021 are being converted to Dec-21 and all the columns for all the months in 2020 are being converted to Jan-2020. There must be something wrong with the calculation, but I can't seem to figure out what it is. Any ideas?
  • Anonymous's avatar
    Anonymous
    5 years ago

    HI Anonymous ,

     

    You can try this.

     

    YYYY-MON = FORMAT(Table[Date],"YYYY-MM")

     

    else in Power Query create a custom Column

     

    =Number.ToText(Date.Year([Date]))&"-"&Number.ToText(Date.Month([Date]))

     

    Regards,
    Harsh Nathani
    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

     

4 Replies

  • Hi Anonymous ,

     

    Try creating a column like this:

    newCol = FORMAT(ClothingSales[Date],"mmm-yy")
     
    Just use your column name in the above DAX.
     
    Thanks,
    Pragati
  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Anonymous ,

     

    You can try this.

     

    YYYY-MON = FORMAT(Table[Date],"YYYY-MM")

     

    else in Power Query create a custom Column

     

    =Number.ToText(Date.Year([Date]))&"-"&Number.ToText(Date.Month([Date]))

     

    Regards,
    Harsh Nathani
    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous the issue I am having now though is that the created column is a string and sorts alphabetically rather than by date. It does not allow me to sort it by the date column because there is more than one date value for the same month. Is there a way I can have the date in this format without converting it to a string?