cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
meddojeddo
Helper IV
Helper IV

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?
1 ACCEPTED SOLUTION
harshnathani
Super User
Super User

HI @meddojeddo ,

 

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)

 

View solution in original post

4 REPLIES 4
harshnathani
Super User
Super User

HI @meddojeddo ,

 

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)

 

@harshnathani 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?

Hi @meddojeddo ,

 

Check if this helps.

 

https://community.powerbi.com/t5/Desktop/Year-Sort/m-p/1657973#M663431

 

You will need to create an index column which will enable you to sort the column.

 

Regards,

Harsh Nathani

Pragati11
Super User
Super User

Hi @meddojeddo ,

 

Try creating a column like this:

newCol = FORMAT(ClothingSales[Date],"mmm-yy")
 
Just use your column name in the above DAX.
 
Thanks,
Pragati

Best Regards,

Pragati Jain

MVP logoDACertAzCert

LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors