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
Anonymous
Not applicable

Filter by Same Month Last Year in Power Query

Hello,

 

I'm having trouble filtering a table in the power query editor to keep only the data from the same current month last year. 

 

For example: It is currently August 2020 and I want to only show the values from August 2019.

 

I'd like the filter to be dynamic so it updates every month. Next month it would show September 2019 etc.

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

You can get that with the following approach

 

1.  Add another query called datefilter.  Add a blank query and put this formula as the source line in the Formula bar

 

= Date.StartOfMonth(Date.From(Date.AddMonths(DateTime.LocalNow(), -12)))

 

2. In your original query, add any date filter to your date column (you will replace it so pick any value).

 

3.  Look at the new filter step in the Formula Bar and replace the hard coded date with "datefilter'

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may go to Query Editor, create a new blank query, rename it as "SameMonthLastYear", copy and paste the codes below into the step "Source", 

 

= Date.AddDays (Date.From (DateTime.LocalNow ()) , -366)

160.png

 

Then go to your fact table query, change the data type of DateKey column to "Date", set it date filter as "After" a date value , such as "4/23/2013".

161.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finally, change the date related codes "4/23/2013" with query name "SameMonthLastYear" like picture below.

162.png

 

 

 

 

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

3 REPLIES 3
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may go to Query Editor, create a new blank query, rename it as "SameMonthLastYear", copy and paste the codes below into the step "Source", 

 

= Date.AddDays (Date.From (DateTime.LocalNow ()) , -366)

160.png

 

Then go to your fact table query, change the data type of DateKey column to "Date", set it date filter as "After" a date value , such as "4/23/2013".

161.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finally, change the date related codes "4/23/2013" with query name "SameMonthLastYear" like picture below.

162.png

 

 

 

 

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Use the formula date.isinpreviousmonth for last month and then date.isincurrentmonth for current month. 

that should do it 

mahoneypat
Employee
Employee

You can get that with the following approach

 

1.  Add another query called datefilter.  Add a blank query and put this formula as the source line in the Formula bar

 

= Date.StartOfMonth(Date.From(Date.AddMonths(DateTime.LocalNow(), -12)))

 

2. In your original query, add any date filter to your date column (you will replace it so pick any value).

 

3.  Look at the new filter step in the Formula Bar and replace the hard coded date with "datefilter'

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.