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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
E9067
Frequent Visitor

Dynamically Filtering TRUNC(SYSDATE) - 1 Without Breaking Query Folding

I have read several questions related to filtering dates without breaking query folding, but none seem to help with my issue. 

 

In Oracle I would write: 

DateColumn BETWEEN TRUNC(SYSDATE, 'YYYY') - 1 AND  TRUNC(SYSDATE) - 1

to filter; however, while attempting the same in Power Query:

each Date.IsInPreviousYear([DateColumn]) and [DateColumn] < Date.From(DateTime.LocalNow())

breaks query folding.

 

Any ideas on how to filter and prevent breaking query folding would be greatly appreciated.

9 REPLIES 9
Anonymous
Not applicable

Just break it up into two separate steps.

Of course, the surest way is always to use a query for your variables, so Query1 is the first day of last year, Query2 is Today's date, and your statement would be

 

each [Date] >= Query1 and < Query2

 

 

--Nate

PwerQueryKees
Super User
Super User

If that does not work, it may be the use of Date.IsInPreviousYear()

The try this

Date.Year([DateColumn]) = (Date.Year(DateTime.FixedLocalNow()) - 1)

I think this is all you need: When datecolumn is in the last year, it certainly is less than DateTime.FixedLocalNow()

Thank you for the feedback. Date.IsInPreviousYear() does not break folding and I have confirmed it is the second portion of the query. Both DateTime.FixedLocalNow() and Date.From(DateTime(LocalNow()) both break folding. The intent is to filter all results to inlcude all of the prior year and YTD not including today. My data is transactional and updates shortly after each transaction; however, measurements are based on full calendar day perfromance and including the current day would skew the results. Thanks again!

You're welcome. Sorry I can not be of more assistance on the query folding question.

But you say


The intent is to filter all results to inlcude all of the prior year and YTD not including today. 

That is what the SQL expression does.

But the PowerQuery expression you are using doesn't do that.

Date.IsInPreviousYear([DateColumn]) and [DateColumn] < Date.From(DateTime.LocalNow())

Lets say DateColumn is today: 22-dec-2024

Then the IsInPrevious year is false and by the use of the AND, the whole expression becomes false. So all YTD dates in 2024 will not be returned by the Table.SelectRows() 

 

Am I mistaken???

A correct expression would be:

Date.Year([DateColumn]) >= (Date.Year(DateTime.FixedLocalNow()) - 1) and [DateColumn] < Date.From(DateTime.LocalNow())
PwerQueryKees
Super User
Super User

Try DateTime.FixedLocalNow()

each Date.IsInPreviousYear([DateColumn]) and [DateColumn] < Date.From(DateTime.FixedLocalNow())

 

lbendlin
Super User
Super User

not exactly clear what date range you are trying to achieve.  Can you specify the filters in the Power Query UI?  If you do that then the chances of folding are higher.

All of the prior year and YTD not including the current day is the end goal. Native UI in Power Query does not allow me to remove the current day dynamically. I can easily filter the prior year and YTD as one step and then have tried adding another step to then filter Is Not Latest; however, if there is no data yet reported for the current day it then filters out yesterday. If I am missing something please let me know. Thank you!

Is this a Direct Query or Import Mode data source?  If it is import mode I would filter the "incomplete day"  out in the UI.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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