Forum Discussion
Transform Text Column into Date Column
- 1 year ago
Hi nove718 ,
I tried reproducing your scenario using sample data, and I was able to achieve the desired output successfully. I've attached a .pbix file for your reference please take a look and review the details.
I created a custom column in Power Query using the following M code to convert your Create date values into proper DateTime format.
let rawText = [CREATE_DATE], formattedText = Text.Start(rawText, 10) & " " & Text.Middle(rawText, 11, 2) & ":" & Text.Middle(rawText, 14, 2) & ":" & Text.Middle(rawText, 17, 2) & "." & Text.Middle(rawText, 20, 3) in try DateTime.FromText(formattedText) otherwise nullFYI:
ā Yugandhar
Community Support Team.
Hi nove718 ,
Please try the following Power Query (M) Code to transform you data to dates:
= DateTime.FromText(Text.Replace(Text.Replace([CREATE_DATE], "-", " "), ".", ":"))
This formula replaces the dash between the date and time with a space, and then replaces the periods with colons to match a standard datetime format. Finally, it applies the DateTime.FromText function to convert the cleaned text into a datetime value.
If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.
Thanks,
Samson
Connect with me on LinkedIn
Check out my Blog
Going to the European Microsoft Fabric Community Conference? Check out my Session