cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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 III
Super User III

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())
Try my new Power BI game Cross the River
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
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors