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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.