Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Shelley
Continued Contributor
Continued Contributor

Need to determine current date, subtract one month and calculate end of month in M

Hello M Query experts, I'm looking for a little help please. I need to filter a column, based on the month end date of the prior month MINUS one year. So, for example, if today is Nov 14, 2019, I want to filter on the date Oct 31,2018. I tried the following, but am getting the error below:

 

= Table.SelectRows(#"Filtered Rows", each [Contract End Date] >=
(Date.AddYears(Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow()), -1))), -1)

 

Expression.Error: 3 arguments were passed to a function which expects 2.
Details:
Pattern=
Arguments=[List]

 

I keep moving around the () and the comma, but still receive errors. What am I missing? Thanks for the help!

 

@Anonymous, @

1 ACCEPTED SOLUTION
KHorseman
Community Champion
Community Champion

I think you've just got some parentheses in the wrong places. I haven't tested this in a real query yet, but I think what you want is:

 

Table.SelectRows(#"Filtered Rows", each [Contract End Date] >=
(Date.AddYears(Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(), -1)), -1)))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @Shelley 

It is easy with DAX in data model.

Create a calculated column

filter date =
DATE ( YEAR ( EOMONTH ( TODAY (), -1 ) ) - 1, MONTH ( EOMONTH ( TODAY (), -1 ) ), DAY ( EOMONTH ( TODAY (), -1 ) ) )

Capture14.JPG

 
For Solution in Power Query, KHorseman has provide a useful solution, please check it.
 
If you have any problem, please feel free to let me know.
 
 
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@Shelley,

What @KHorseman said. I just want to add that the right side of the argument will return DateTime format so you might need to encapsulate it within Date.From function to convert it into Date format for comparision, assuming your Contract End Date is in Date format. 

KHorseman
Community Champion
Community Champion

I think you've just got some parentheses in the wrong places. I haven't tested this in a real query yet, but I think what you want is:

 

Table.SelectRows(#"Filtered Rows", each [Contract End Date] >=
(Date.AddYears(Date.EndOfMonth(Date.AddMonths(DateTime.LocalNow(), -1)), -1)))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




This looks like something I need help with,

 

I am looking for something similar for Power Querry Editor but for everying before the previous month.

I have tried to make changes to this formula but being a novice I cant see to get it to work

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.