Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
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
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.
Hi
If you want last 12 months then
.... [sdate] >=...
Stéphane
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.