cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shelley Member
Member

How to Calculate the first day of the Month in Power Query

Hi All, I'm sure I'm missing some syntax and just can't get this right. I want to bring in all the records with an order submit date < the first date of the current month. #"Filtered Rows1" = Table.SelectRows(#"Replaced Errors1", each [Order_Submit_Date] < Date.StartOfMonth(#date(DateTime.Date(DateTime.LocalNow())))) I'm receiving an error "OLE DB or ODBC error: {Expression.Error] 1 arguments were passed to a function which expects 3.. What the heck am I doing wrong?
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to Calculate the first day of the Month in Power Query

hi, @Shelley

You may try to divide your #"Filtered Rows1" into two steps, this will be a simple issue.

Step1:

Add a first day of the Month column and change the type of it to date

=Date.StartOfMonth(DateTime.LocalNow())

5.JPG

Step2:

Use this code to filter data

= Table.SelectRows(#"Changed Type1", each [Date] < [Custom])

Result:

6.JPG

 

Of course, you could remove Custom column later.

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
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
Super User
Super User

Re: How to Calculate the first day of the Month in Power Query

@Shelley

 

what if you use this. No need for #date i think

 

Date.StartOfMonth(DateTime.LocalNow())
Shelley Member
Member

Re: How to Calculate the first day of the Month in Power Query

Okay, have it running with no error, but it's not working correctly. #"Filtered Rows1" = Table.SelectRows(#"Replaced Errors1", each [Order_Submit_Date] < #date(Date.StartOfMonth(#date(DateTime.Date(DateTime.LocalNow()) )))) Gives me everything < 1/7/2019. I want < 1/1/2019.
Community Support Team
Community Support Team

Re: How to Calculate the first day of the Month in Power Query

hi, @Shelley

You may try to divide your #"Filtered Rows1" into two steps, this will be a simple issue.

Step1:

Add a first day of the Month column and change the type of it to date

=Date.StartOfMonth(DateTime.LocalNow())

5.JPG

Step2:

Use this code to filter data

= Table.SelectRows(#"Changed Type1", each [Date] < [Custom])

Result:

6.JPG

 

Of course, you could remove Custom column later.

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
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

Shelley Member
Member

Re: How to Calculate the first day of the Month in Power Query

This appears to work, Lin. The only thing is that it seems to run super slow, but I don't know if it has to do with this script or if its our network or server or something else. Thanks for your help!

 

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Users Online
Currently online: 363 members 3,196 guests
Please welcome our newest community members: