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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
jaz1003
New Member

Error While converting to date format

Hello, Everyone . I am getting an error while convering my data to DATE/TIME format. I have attached a screenshot of the sameScreenshot 2023-08-01 150713.png

3 REPLIES 3
Rickmaurinus
Helper V
Helper V

Jaz,

Power Query is sometimes smart enough to recognize a format for a datetime value. However, in cases where it fails, it can be helpful to be very specific what format it should expected. 

 

For example, if you add a new column and try to extract a datetime value from the DISP column you could write: 

 

Table.AddColumn(
  #"Promoted Headers", 
  "DateTimeValue", 
  each DateTime.FromText( [DISP], [Format = "yyyy-MM-dd h:mm:ss tt"]), 
  DateTime.Type 
)

 


Since you already have existing column, it may be easier to use a format like: 

 

Table.TransformColumns( 
  #"Promoted Headers", 
  {{"DISP", each DateTime.FromText( _, [Format = "yyyy-MM-dd h:mm:ss tt"]), DateTime.Type }} 
)

 

To extend this for other columns you can add additional lines. 

Table.TransformColumns( 
  #"Promoted Headers", 
  {{"DISP", each DateTime.FromText( _, [Format = "yyyy-MM-dd h:mm:ss tt"]), DateTime.Type },
   {"ARRIVED", each DateTime.FromText( _, [Format = "yyyy-MM-dd h:mm:ss tt"]), DateTime.Type }} 
)

The formatting strings can be a bit tricky, but you can find documentation on the different expected strings for this at: 

https://powerquery.how/datetime-totext/ 

https://powerquery.how/date-totext/

 

And here's a working example that you can paste into the advanced editor: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvEMDlCK1YlWMjIwMtY1MNU1NlQwtjI1sTIxVXD0RZcxtTIwsTIwBMvEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Added Custom" = Table.AddColumn(#"Promoted Headers", "DateTimeValue", each DateTime.FromText( [DISP], [Format = "yyyy-MM-dd h:mm:ss tt"]), DateTime.Type ),
    Custom1 = Table.TransformColumns( #"Added Custom", {{"DISP", each DateTime.FromText( _, [Format = "yyyy-MM-dd h:mm:ss tt"]), DateTime.Type }} )
in
    Custom1

Hope that helps!

 

Regards,

Rick

--------------------------------------------------

@ me in replies or I'll lose your thread

 

Master Power Query M? -> https://powerquery.how

Read in-depth articles? -> BI Gorilla

Youtube Channel: BI Gorilla

 

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

Syk
Super User
Super User

What does the data look like before that step?

When I load that data it seems to be in Alphanumeic valueScreenshot 2023-08-01 162712.png

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors