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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
dave_schultz
Regular Visitor

Dynamic date/time change

Hi there,

 

Everyday, I want to add a dynamic filter looking at two day's ago with the the earliest time. For example for this morning: today is 2022-12-08. I want to get: 2022-12-08-0-0-0. Here is what i got: 

 

let
Source = DateTime.LocalNow(),
#"Converted to Table" = #table(1, {{Source}}),
#"Added Custom1" = Table.AddColumn(#"Converted to Table", "Custom.1", each Date.AddDays([Column1],-2)),
#"date and time" = #"Added Custom1"{0}[Custom.1]
in
#"date and time"

 

It's pulling the current 2 day's ago date and time. I always want midnight.

2 ACCEPTED SOLUTIONS
dave_schultz
Regular Visitor

Hi @vicky_ 

 

Thanks for responding. Looks like that returns only the date.

View solution in original post

Anonymous
Not applicable

Hi @dave_schultz ,

 

Try the Date.StartOf Day function. It returns the start of the day represented by dateTimedateTime must be a datedatetime, or datetimezone value.

vstephenmsft_0-1670570449667.pngvstephenmsft_1-1670570460870.png

let
Source = DateTime.LocalNow(),
#"Converted to Table" = #table(1, {{Source}}),
#"Added Custom1" = Table.AddColumn(#"Converted to Table", "Custom.1", each Date.StartOfDay(Date.AddDays([Column1],-2)))
in
    #"Added Custom1"

 

 

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.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @dave_schultz ,

 

Try the Date.StartOf Day function. It returns the start of the day represented by dateTimedateTime must be a datedatetime, or datetimezone value.

vstephenmsft_0-1670570449667.pngvstephenmsft_1-1670570460870.png

let
Source = DateTime.LocalNow(),
#"Converted to Table" = #table(1, {{Source}}),
#"Added Custom1" = Table.AddColumn(#"Converted to Table", "Custom.1", each Date.StartOfDay(Date.AddDays([Column1],-2)))
in
    #"Added Custom1"

 

 

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 @Anonymous - Yes, this answered my question. Thank you!

 

David

dave_schultz
Regular Visitor

Hi @vicky_ 

 

Thanks for responding. Looks like that returns only the date.

vicky_
Super User
Super User

You could try converting the date time to just a date (I think that would make it midnight) with something like: 

DateTime.Date(DateTime.LocalNow())

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.