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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
Resident Rockstar
Resident Rockstar

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors