Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
JennyMilf
Frequent Visitor

Convert text to Date

Hi everyone,

How can I convert Year-month from text to Date? 

I tried: YearMonth_Date = DATE(LEFT(Table[YearMonth], 4), RIGHT(Table[YearMonth], 2), 1) but it's not work

Thank you

JennyMilf_0-1675847302449.png

 

 

7 REPLIES 7
FreemanZ
Super User
Super User

hi @JennyMilf 

what do you get with this:

YearMonth_Date = DATE(LEFT(Table[YearMonth], 4), RIGHT(Table[YearMonth], 2), 1)

?

JennyMilf
Frequent Visitor

How about Month_hoa convert to Date (just show month number)?

 

Hi @JennyMilf 

You can refer to the following calculated column:

 

YearMonth_Date = CONVERT([Year-Month],DATETIME)

Month_num=MONTH(CONVERT([Month_hoa]&" "&"1",DATETIME))

 

vxinruzhumsft_0-1675925349452.png

Best Regards!

Yolo Zhu

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

 

Anonymous
Not applicable

=SWITCH([Month Name],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,"Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12,"Invalid Month")

 
Try this 🙂 
Anonymous
Not applicable

Could you give more of an explanation please? You already have activate date, then Year Month that i'm assuming comes from activate date. It look like you're trying to recreate activate date? I'm not sure what you're trying to do. 

Could you give an example output. You may need to use CONVERT() to turn your string into a date format. Let me know and i'll get straight back to you 🙂 good luck

Anonymous
Not applicable

U can simply change text to date format in PQ if that does not work. There are also plenty of solutions to this question online. Please google before posting.
See for instance:
Solved: Converting text year to date in Power Query - Microsoft Power BI Community
Solved: Convert string to date - Microsoft Power BI Community
Solved: Converting from Text to Date - Microsoft Power BI Community

There are loads more online.
"Text to date Power BI"

jaweher899
Super User
Super User

please try 

 

YearMonth_Date = DATE(
YEAR(DATEVALUE("01-" & RIGHT(Table[YearMonth], 2) & "-" & LEFT(Table[YearMonth], 4))),
MONTH(DATEVALUE("01-" & RIGHT(Table[YearMonth], 2) & "-" & LEFT(Table[YearMonth], 4))),
1
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.