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
hamzashafiq
Kudo Collector
Kudo Collector

Filter data for Last 12 Months using Power Query

Dear All,

 

I have a table, I want to filter it for Last 12 Months on the data column which I have in the table. For example the max date I have in the data is 25/05/2022, the filter data should be between 26/05/2022 and 25/05/2022. I can do this using DAX but I want to get this done on Power Query before loading the data in report. 

1 ACCEPTED SOLUTION
ribisht17
Super User
Super User

@hamzashafiq 

 

Please check Solved: How to limit power query to last 12 months of data... - Microsoft Power BI Community

 

Thanks,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

View solution in original post

2 REPLIES 2
rohit_singh
Solution Sage
Solution Sage

Hi @hamzashafiq ,

I assume there is a typo and your date range is 26/05/2021 to 25/05/2022. 

Consider my date table that has max date = today's date as shown below

rohit_singh_0-1653492624027.png

 

2) Open a new blank query and create a parameter for max date

 

= List.Max(dim_date[Date])

 

rohit_singh_1-1653492760680.png

3) Similarly, create a parameter for min date

= Date.AddMonths(List.Max(dim_date[Date]), -12)

rohit_singh_2-1653492891434.png

 

4) Filter your data table using these parameters 

rohit_singh_3-1653492954894.png

 

5) Choose any random dates since we will be replacing these with parameters that we created above

rohit_singh_4-1653493007749.png


6) Replace the dates with the parameters and your data will be filtered as per the query

rohit_singh_5-1653493187088.png

 

Please do keep in mind that you cannot create parameters from and use it to filter the same table, since you will get a cyclic reference error. 

rohit_singh_6-1653493460512.png


I've created the parameters using my date table and filtered a copy of the date table using it.

Hence, I would suggest choosing the date column and adding it as a new query to compute your min date parameter

rohit_singh_7-1653493612724.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂




ribisht17
Super User
Super User

@hamzashafiq 

 

Please check Solved: How to limit power query to last 12 months of data... - Microsoft Power BI Community

 

Thanks,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

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.