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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
johnf
Helper I
Helper I

Time calculation with DirectQuery

Hi,

 

Trying to figure out how to automatically filter a visualisation to show only rows that are up to 180 days from NOW() in DirectQuery

 

I have a column that has a date/time stamp but I only want to show rows that are within 180 days of when the report is viewed.

 

Can anyone assist?

 

Thanks,

John

1 ACCEPTED SOLUTION

@johnf

 

You can add a custom column with Power Query in query editor like below.

let
    Source = Sql.Databases("HERBERTSQL2016"),
    #"Calculated Measure" = Source{[Name="Calculated Measure"]}[Data],
    #"dbo_Time calculation with DirectQuery" = #"Calculated Measure"{[Schema="dbo",Item="Time calculation with DirectQuery"]}[Data],
    #"Added Conditional Column" = Table.AddColumn(#"dbo_Time calculation with DirectQuery", "Custom", each if [Date] >= Date.AddDays(DateTime.Date(DateTime.LocalNow()), 180) then "N" else if [Date] < DateTime.Date(DateTime.LocalNow()) then "N" else "Y" )
in
#"Added Conditional Column"

Time calculation with DirectQuery_1.jpg

 

You can also use the SQL statement when connect the SQL DB.

Select * From [Time calculation with DirectQuery] where [Time calculation with DirectQuery].Date >= GetDate() and [Time calculation with DirectQuery].Date < Dateadd(day, 180, GetDate())"]

Time calculation with DirectQuery_2.jpg

 

Best Regards,

Herbert

View solution in original post

2 REPLIES 2
johnf
Helper I
Helper I

I've found one solution to this which is to create a column with the following calculation

 

Within 180 days = IF([Date]>=NOW()+180,"N",IF([Date]<NOW(),"N","Y"))

 

I can then use this to filter on. One thing that was confusing me in this was that in the editor when I entered the NOW() function it was being greyed out with a red squiggle line underneath which I was interpreting as meaning it wasn't valid in DirectQuery.

 

Apparently though, it works.

 

Interested if anyone has another solution.

@johnf

 

You can add a custom column with Power Query in query editor like below.

let
    Source = Sql.Databases("HERBERTSQL2016"),
    #"Calculated Measure" = Source{[Name="Calculated Measure"]}[Data],
    #"dbo_Time calculation with DirectQuery" = #"Calculated Measure"{[Schema="dbo",Item="Time calculation with DirectQuery"]}[Data],
    #"Added Conditional Column" = Table.AddColumn(#"dbo_Time calculation with DirectQuery", "Custom", each if [Date] >= Date.AddDays(DateTime.Date(DateTime.LocalNow()), 180) then "N" else if [Date] < DateTime.Date(DateTime.LocalNow()) then "N" else "Y" )
in
#"Added Conditional Column"

Time calculation with DirectQuery_1.jpg

 

You can also use the SQL statement when connect the SQL DB.

Select * From [Time calculation with DirectQuery] where [Time calculation with DirectQuery].Date >= GetDate() and [Time calculation with DirectQuery].Date < Dateadd(day, 180, GetDate())"]

Time calculation with DirectQuery_2.jpg

 

Best Regards,

Herbert

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.