Mass transform different formats of time data in a column --- using power query

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
400
Office Version
  1. 365
Platform
  1. Windows
Hi Gurus,
I have a dataset with a column of time data that looks like this:
1742878460448.png

basically it contains two forms of time I know how to tranform into one format in excel with additional column but i heard power query can process data much faster. Thank you!
 
Hi @yxz152830,

An attempt

Power Query:
let
A = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
B = {"Column1", "Column2"}, // Columns to be modified
C = Table.TransformColumns(A, List.Transform(B, each {_, each ((x)=> try #date(x{2},x{0},x{1}) otherwise #date(x{2},x{1},x{0}))
    (List.Transform(List.FirstN(Text.SplitAny(Text.From(_), "-/ "),3), Number.From))})) in C

Regards,
 
Upvote 0
Sorry, I didn't understand.

Power Query:
let
A = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
B = {"Column1", "Column2"}, // Columns to be modified
C = Table.TransformColumns(A, List.Transform(B, each {_, each ((x)=> #date(x{2},x{1},x{0}))
    (List.Transform(List.FirstN(Text.SplitAny(Text.From(_), "-/ "),3), Number.From))})) in C

Regards,
 
Upvote 0
All UI based solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Date", type date}})
in
    #"Changed Type1"
Book1
CDEF
2DateDate
3 2/04/2016 12:00:00 AM2/04/2016
49/07/2016 12:00:00 AM9/07/2016
527-02-201627/02/2016
616-01-201616/01/2016
718-02-201718/02/2017
Sheet1
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top