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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Is it possible to store DateTime.LocalNow() as a scalar variable without creating new column?

Hi there, this problem has had me stuck for a little while. 

All I'm trying to do is filter the table so that it keeps rows with a date greater than 7 days old. To do so, I'm simply using the [Date] column from the table and comparing it to DateTime.LocalNow()

Previously, I generated a new column and compared the dates that way:

hunterfeldman_0-1617719397639.png

(note: I recognize both functions reference #"Filter Packet Turned In" but it's just a quick recreation of what I had)

However I'm wondering if there is way to avoid generating a new column and instead store the current day as a variable/function that can be referenced. I tried the process below but got the following error:

hunterfeldman_1-1617719616316.png

hunterfeldman_2-1617719667334.png



Appreciate any help!

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Something like this (with your own fields):

= Table.SelectRows(#"previous Step", each Duration.Days(  Date.From(DateTime.LocalNow()) - [Date] ) >  7)

View solution in original post

4 REPLIES 4
HotChilli
Super User
Super User

You can declare a variable if you want to:

 

let thedate = Date.From(DateTime.LocalNow()) in

Anonymous
Not applicable

Alright so the variable 'thedate' needs to be in it's own let-in environment, seperate (or nested) from the main let-in environment of the query? 

HotChilli
Super User
Super User

Something like this (with your own fields):

= Table.SelectRows(#"previous Step", each Duration.Days(  Date.From(DateTime.LocalNow()) - [Date] ) >  7)
Anonymous
Not applicable

Ok so the Date.From(DateTime.LocalNow()) has to be called in the Table function? It can't be stored as its own seperate variable and be called like I showed in my example?

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.