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.
Hello, anyone experiencing a bug using Date.EndOfMonth in PowerQuery M.
I was working on a report for some reason I'm not getting the results I needed, after few hours of peeling each part of the report I tested the accuracy of EndOfMonth
Here is the sample code I use to test:
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom1", each DateTimeZone.FromText("2011-02-21T12:30:00-08:00")), #"Added Custom" = Table.AddColumn(#"Added Custom1", "Custom", each Date.EndOfMonth([Custom1]))
Here is the Actual Result:
2011-03-01 12:00:00 AM -08:00
Here is the Expected Result:
2011-02-28T23:59:59-08:00
This example is from: https://docs.microsoft.com/en-us/powerquery-m/date-endofmonth
Solved! Go to Solution.
Hi @justin777 ,
The PG team have replied me as below:
What the customer is seeing is actually due to rounding that occurs when displaying values in the PQ Editor (which mimics Excel’s rounding display behavior). If you click on the rightmost cell, you’ll see the full value:
2011-02-28T23:59:59.9999999-08:00
If you convert the rightmost column to a date, you should see the same result as in Test.
Hope it could help you.
Regards,
Daniel He
Hi @justin777,
Based on my test, it could work on my side with below code in query editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtNA30jc0UYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.EndOfMonth([Date])) in #"Added Custom"
Regards,
Daniel He
Hi v-danghe-msft,
Looks like having it decompress from Binary works just fine but on my usecase of using the method on a DateTime would lead to a wrong output. I incorporated your code to mine:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtNA30jc0UYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.EndOfMonth([Date])), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom1", each DateTimeZone.FromText("2011-02-21T12:30:00-08:00")), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom2", each Date.EndOfMonth([Custom1])) in #"Added Custom2"
Still the same outcome:
I realized I'm getting the wrong outcome because I am using the DateTime and the method Date.EndOfMonth doesn't support the data type properly.
So when I change the data type to Date, it now gives the correct End Date.
I suggest changing the example in: https://docs.microsoft.com/en-us/powerquery-m/date-endofmonth
Since the example is, which would lead to a wrong outcome as seen in the screenshot above:
dateTime = DateTimeZone.FromText("2011-02-21T12:30:00-08:00"); Date.EndOfMonth(dateTime) equals 2011-02-28T23:59:59-08:00
Hi @justin777 ,
The PG team have replied me as below:
What the customer is seeing is actually due to rounding that occurs when displaying values in the PQ Editor (which mimics Excel’s rounding display behavior). If you click on the rightmost cell, you’ll see the full value:
2011-02-28T23:59:59.9999999-08:00
If you convert the rightmost column to a date, you should see the same result as in Test.
Hope it could help you.
Regards,
Daniel He
Hi @justin777 ,
I have asked the PG team for this porblem and I will reply you as soon as I receive any useful information.
Regards,
Daniel He
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 |
---|---|
114 | |
100 | |
88 | |
69 | |
61 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |