DateTime.IsInPreviousNSeconds

DateTime

Returns true if the datetime falls within the previous N seconds.

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

Syntax

DateTime.IsInPreviousNSeconds(dateTime as any, seconds as number) as logical

Parameters

NameTypeRequiredDescription
dateTimeanyYesA datetime or datetimezone value to test.
secondsnumberYesThe number of seconds back to include. Must be a positive integer.

Return Value

logicaltrue if the datetime falls within the N seconds before the current second, false otherwise.

Remarks

DateTime.IsInPreviousNSeconds returns true if the input datetime or datetimezone value falls within the N complete seconds preceding the current second. The current second is not included; use DateTime.IsInCurrentSecond to also match the current second. The function is re-evaluated on each query refresh.

Examples

Example 1: Filter events from the previous 30 seconds

Table.SelectRows(
    Events,
    each DateTime.IsInPreviousNSeconds([EventTime], 30)
)
Result
EventID
EventTime
1683/8/2026 10:32:16 AM
2693/8/2026 10:32:40 AM

Example 2: Flag events from the past 60 seconds

Table.AddColumn(
    Events,
    "InPrev60Sec", each DateTime.IsInPreviousNSeconds([EventTime], 60), type logical
)
Result
EventID
EventTime
InPrev60Sec
1663/8/2026 10:31:30 AMFALSE
2683/8/2026 10:32:16 AMTRUE
3703/8/2026 10:32:46 AMFALSE

Compatibility

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