Forum Discussion
convert to date format
- 5 years ago
Hi, Anonymous
column:
Column = IFERROR(FORMAT(('Table'[Column1]-DATE(1899,12,30))+DATE(1899,12,30),"mm/dd/yyyy"),BLANK())measure:
Measure = IFERROR(FORMAT((MAX('Table'[Column1])DATE(1899,12,30))+DATE(1899,12,30),"mm/dd/yyyy"),BLANK())result:
Zerrick
Did I answer your question? Mark my post as a solution!
Hi, mahoneypat
You are absolutely right, obviously I am still not familiar with the PoweQuery language. It definitely saves a lot of steps.
But what confuses me is that in Excel it seems that the first day is January 1, 1900, and the result I get after converting the numbers to dates in Power BI indicates that the first day should be December 30, 1899, which is a little strange.
But your formula is definitely correct anyway. Thanks for sharing.
Anonymous if you want to get result in Power Query, here is the improved M code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY3MtU3MjAyVIrViVYyMTEyNgOzgOJGqOKWYBaYUFCKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
a = Table.AddColumn(#"Changed Type", "1899-12-30", each try Date.From([Column1]) otherwise Date.AddDays(#date(1899,12,30), Number.FromText([Column1])))//,
//b = Table.AddColumn(a, "1900-1-1", each try Date.From([Column1]) otherwise Date.AddDays(#date(1900,1,1), Number.FromText([Column1])))
in
a//b
Zerrick
Did I answer your question? Mark my post as a solution!
Thanks for that correction. I didn't check the math on the date change. I checked it with today's date (44409 as integer in Excel), and had to update the formula to this instead.
= try Date.From([Date]) otherwise Date.AddDays(#date(1899,12,31), Number.FromText([Date])-1)
Pat