DateTime.IsInNextNHours

DateTime

Returns true if the datetime falls within the next N clock hours.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

DateTime.IsInNextNHours(dateTime as any, hours as number) as logical

Parameters

NameTypeRequiredDescription
dateTimeanyYesA datetime or datetimezone value to test.
hoursnumberYesThe number of hours ahead to include. Must be a positive integer.

Return Value

logicaltrue if the datetime falls within the next N hours after the current hour, false otherwise.

Remarks

DateTime.IsInNextNHours returns true if the input datetime or datetimezone value falls within the next N complete clock hours after the current hour. The current hour itself is not included — use DateTime.IsInCurrentHour to also include the current hour. The function is re-evaluated on each query refresh, and the hours argument must be a positive integer.

Like all DateTime.IsIn* functions, the reference clock is DateTime.LocalNow(). In Power BI Service and Dataflows, "local" typically means the cloud region's UTC time rather than your personal timezone. Be aware of this when building hour-level filters in cloud-refresh scenarios.

DateTime.IsInNextNHours is more practical than DateTime.IsInNextHour for use cases that require a meaningful lookahead window — for example, flagging scheduled maintenance events in the next 4 hours, or surfacing SLA-critical orders due in the next 8 hours.

Examples

Example 1: Filter log entries in the next 4 clock hours

Table.SelectRows(
    OrderLog,
    each DateTime.IsInNextNHours([Timestamp], 4)
)
Result
LogID
OrderID
Action
Timestamp
DurationMinutes
Notes

Example 2: Flag entries in the next 8 hours

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(OrderLog, 4), {"LogID", "Timestamp"}),
    "InNext8Hours", each DateTime.IsInNextNHours([Timestamp], 8), type logical
)
Result
LogID
Timestamp
InNext8Hours
1L0011/15/2024 9:30:00 AMFALSE
2L0021/16/2024 2:15:00 PMFALSE
3L0031/18/2024 11:00:00 AMFALSE
4L0041/20/2024 8:45:00 AMFALSE

Example 3: Combine current hour and next N hours for a full lookahead window

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(OrderLog, 4), {"LogID", "Timestamp"}),
    "In7HourWindow",
    each DateTime.IsInCurrentHour([Timestamp]) or DateTime.IsInNextNHours([Timestamp], 6),
    type logical
)
Result
LogID
Timestamp
In7HourWindow
1L0011/15/2024 9:30:00 AMFALSE
2L0021/16/2024 2:15:00 PMFALSE
3L0031/18/2024 11:00:00 AMFALSE
4L0041/20/2024 8:45:00 AMFALSE

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks