cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

A bug in Date.EndOfMonth resulting the start of next month

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: A bug in Date.EndOfMonth resulting the start of next month

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

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Highlighted
Microsoft
Microsoft

Re: A bug in Date.EndOfMonth resulting the start of next month

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"

1.PNG

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Frequent Visitor

Re: A bug in Date.EndOfMonth resulting the start of next month

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  

 

Highlighted
Microsoft
Microsoft

Re: A bug in Date.EndOfMonth resulting the start of next month

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

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Microsoft
Microsoft

Re: A bug in Date.EndOfMonth resulting the start of next month

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

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors