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
whatisdata96
Helper I
Helper I

How to add a custom column to check if a date is within 12 hours from now?

Hi all - the title says it all. 

 

I have call center data that shows when agents will submit tickets. I have one date/time column that is called "Created Time". I want to add a conditional/custom column that would check if this date in that column is dynamically within 12 hours of right NOW dynamically.

 

Should I not do this in Power Query? Should I open up Power Pivot and do this in DAX? My end hope is to make it possible to throw all the data into a Pivot and filter if the data is within that 12-hour window of the date/time now.

 

Appreciate any help here.

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Since calculated columns (whether DAX or Power Query) only update upon refreshing the data model, you may want to consider writing a measure that you can use as a filter on a visual.

 

For example, if your measure looked something like this (untested):

IsInNext12Hours =
VAR _DateToCompare = MAX ( Table1[Date] )
VAR _HourDiff = DATEDIFF ( NOW (), _DateToCompare, HOUR )
RETURN
    IF ( _HourDiff < 12, 1, 0 )

 

Then you could set [IsInNext12Hours] is 1 in the filter pane of a visual.

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

Since calculated columns (whether DAX or Power Query) only update upon refreshing the data model, you may want to consider writing a measure that you can use as a filter on a visual.

 

For example, if your measure looked something like this (untested):

IsInNext12Hours =
VAR _DateToCompare = MAX ( Table1[Date] )
VAR _HourDiff = DATEDIFF ( NOW (), _DateToCompare, HOUR )
RETURN
    IF ( _HourDiff < 12, 1, 0 )

 

Then you could set [IsInNext12Hours] is 1 in the filter pane of a visual.

edhans
Super User
Super User

You want to use the DateTime.IsInNextNHours() function. As of the time of this posting, 4pm on August 4 is within 12hrs, 4pm of August 5th is not.

edhans_0-1659637716054.png

That will only happen on the refresh though. Once it is in Power BI it will go "stale" unless you are frequently refreshing (more frequently than every 12 hrs. A Calculated Column in DAX would have the same issue - it only updates on refresh.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.

Top Kudoed Authors