DateTime.IsInNextNHours
DateTimeReturns true if the datetime falls within the next N clock hours.
Syntax
DateTime.IsInNextNHours(dateTime as any, hours as number) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A datetime or datetimezone value to test. |
hours | number | Yes | The number of hours ahead to include. Must be a positive integer. |
Return Value
logical — true 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)
)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
)LogID | Timestamp | InNext8Hours | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | FALSE |
| 2 | L002 | 1/16/2024 2:15:00 PM | FALSE |
| 3 | L003 | 1/18/2024 11:00:00 AM | FALSE |
| 4 | L004 | 1/20/2024 8:45:00 AM | FALSE |
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
)LogID | Timestamp | In7HourWindow | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | FALSE |
| 2 | L002 | 1/16/2024 2:15:00 PM | FALSE |
| 3 | L003 | 1/18/2024 11:00:00 AM | FALSE |
| 4 | L004 | 1/20/2024 8:45:00 AM | FALSE |