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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
needhelp89
Frequent Visitor

Power Query M Trailing 12 Months

Hello, 

 

I am fairly new to Power Query and I am trying to pull in the last 12 months of data. Here is what I have but even if I do one month instead of 12 for testing it runs and runs millions of rows when it shouldn't be that much. Any idea what i am doing wrong?

 

= Table.SelectRows(dbo_CON_INCOME_STATEMENT, each ([BookName] = "Accrual") and ([sdate] <= Date.AddMonths(Date.StartOfMonth(DateTime.LocalNow()), -12)))

 

I am able to pull in specific months, see below, and it works fine. Just want to change it to last 12 months so I don't have to manually update in the future.

 

= Table.SelectRows(dbo_CON_INCOME_STATEMENT, each ([BookName] = "Accrual") and ([sdate] = #date(2023, 1, 1) or [sdate] = #date(2023, 2, 1)

 

Thank you 

2 REPLIES 2
Anonymous
Not applicable

Hi @needhelp89 ,

 

One way to optimize the query is to use the "StartOfMonth" function to get the start of the month for the current date, and then subtract 12 months to get the start of the month for the date 12 months ago. You can then use this value to filter the table. Here is an example of how you can modify your query:

= Table.SelectRows(dbo_CON_INCOME_STATEMENT, each ([BookName] = "Accrual") and ([sdate] >= Date.StartOfMonth(Date.AddMonths(DateTime.LocalNow(), -12))))

This should return the last 12 months of data for the "Accrual" book.

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

slorin
Super User
Super User

Hi

If you want last 12 months then 

.... [sdate] >=...

 

Stéphane

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors