Skip to content

Commit 43ea596

Browse files
authored
Create 2024-06-Convert-Column-With-Multiple-Date-Formats.pq
1 parent 1c22dee commit 43ea596

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let
2+
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtE1MNY1NFGK1YlWArN0QYJKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateString = _t]),
3+
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DateString", type text}}),
4+
format1 = "yyyy-MM-dd",
5+
format2 = "MM-dd-yyyy",
6+
7+
#"Added Custom" = Table.AddColumn(#"Changed Type", "Date",
8+
(row) =>
9+
try
10+
Date.FromText( row[DateString], [ Format = format1, Culture = "en-us" ] )
11+
catch (e1) =>
12+
try
13+
Date.FromText( row[DateString], [ Format = format2, Culture = "en-us" ] )
14+
catch (e2) => error "Failed both dates",
15+
type date
16+
)
17+
in
18+
#"Added Custom"

0 commit comments

Comments
 (0)