Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have date column as text the format is DMMYYYY, I need to transform it to YYYY-MM-DD. Please help. Thanks
Solved! Go to Solution.
Hi @idramadhara ,
Assuming your original text date column is called [dateText], enter this as a new custom column:
Text.Combine(
{
Text.End([dateText], 4),
Text.Range([dateText], Text.Length([dateText]) - 6, 2),
Text.PadStart(Text.Start([dateText], Text.Length([dateText]) - 6), 2, "0")
},
"-"
)
This outputs in a text format, but will also be recognised perfectly by PQ if you want to convert to native date type.
Example output:
Full example query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMDICIqVYHRAHwQaz4BwktqWhIZBtDNFgamAOkYgFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [dateText = _t]),
addDate = Table.AddColumn(Source, "date", each
Text.Combine(
{
Text.End([dateText], 4),
Text.Range([dateText], Text.Length([dateText]) - 6, 2),
Text.PadStart(Text.Start([dateText], Text.Length([dateText]) - 6), 2, "0")
},
"-"
)
)
in
addDate
Pete
Proud to be a Datanaut!
Hi @idramadhara ,
Assuming your original text date column is called [dateText], enter this as a new custom column:
Text.Combine(
{
Text.End([dateText], 4),
Text.Range([dateText], Text.Length([dateText]) - 6, 2),
Text.PadStart(Text.Start([dateText], Text.Length([dateText]) - 6), 2, "0")
},
"-"
)
This outputs in a text format, but will also be recognised perfectly by PQ if you want to convert to native date type.
Example output:
Full example query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMDICIqVYHRAHwQaz4BwktqWhIZBtDNFgamAOkYgFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [dateText = _t]),
addDate = Table.AddColumn(Source, "date", each
Text.Combine(
{
Text.End([dateText], 4),
Text.Range([dateText], Text.Length([dateText]) - 6, 2),
Text.PadStart(Text.Start([dateText], Text.Length([dateText]) - 6), 2, "0")
},
"-"
)
)
in
addDate
Pete
Proud to be a Datanaut!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
102 | |
48 | |
19 | |
13 | |
11 |