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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jowildes
New Member

Trouble converting Date from Text

Hello,

I'm hoping someone here has experienced this.  I have two columns that I have split, the original data is text, and the values are text representation of dates in the mmddyyyy format. Screenshot of the data is further below. I want to be able to convert the text value to date type.  When I select Date/Time, or Date from the Data Type drop down I get an error from Power Query.  

 

DataFormat.Error: We couldn't parse the input provided as a Date value.
Details:
07182022 <-this is how my date is formatted

 

DataFormat.Error: We couldn't parse the input provided as a DateTime value.
Details:
07182022

 

If I attempt to use the Date.FromText , I get an error that the format includes a TIME VALUE ...I don't really care about the time, I just need it to register as a date when in Excel.

 

I can get around this by loading the data and not formatting it as Date, but then using the Text-to-Column feature and changing the data to date format MDY in the Text-to-Column wizard.  it works flawlessly there, but I don't want to have the user go through this every time they refresh the data.  

 

Thoughts on how to do this?

 

2022-11-08_08-00-43.jpg

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @jowildes 

 

You'll need to parse the text into parts so PQ knows what to do with it.  Without any delimiter between the mm dd and yyyy parts, it doesn't know what is what.

 

Add a Custom Column with this code

 

Date.From( Text.Middle([StartDate] , 0 , 2) & "-" & Text.Middle([StartDate] , 2 , 2) & "-" & Text.Middle([StartDate] , 4 , 4) , "en-US" )

 

 

Download example PBIX file

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

1 REPLY 1
PhilipTreacy
Super User
Super User

Hi @jowildes 

 

You'll need to parse the text into parts so PQ knows what to do with it.  Without any delimiter between the mm dd and yyyy parts, it doesn't know what is what.

 

Add a Custom Column with this code

 

Date.From( Text.Middle([StartDate] , 0 , 2) & "-" & Text.Middle([StartDate] , 2 , 2) & "-" & Text.Middle([StartDate] , 4 , 4) , "en-US" )

 

 

Download example PBIX file

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors