Date.IsInPreviousNDays

Date

Returns true if the date falls within the previous N days (not including today).

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

Syntax

Date.IsInPreviousNDays(dateTime as any, days as number) as logical

Parameters

NameTypeRequiredDescription
dateTimeanyYesA date, datetime, or datetimezone value to test.
daysnumberYesThe number of days back to include. Must be a positive integer.

Return Value

logicaltrue if the date falls within the N days before today, false otherwise.

Remarks

Date.IsInPreviousNDays returns true if the input date falls within the N days immediately preceding today. Today itself is not included; use Date.IsInCurrentDay to also match today. The function is re-evaluated on each query refresh.

For example, with days = 7, it matches any date from 7 days ago through yesterday — a 7-day window ending yesterday. This is useful for rolling lookback windows such as "last 7 days," "last 30 days," or "last 90 days."

Note that Date.IsInPreviousNDays(d, 1) is equivalent to Date.IsInPreviousDay. To include today in the window, add or Date.IsInCurrentDay([OrderDate]). The window is based on whole calendar days, not a 24-hour rolling period from the current time.

Examples

Example 1: Filter orders from the past 30 days

Table.SelectRows(
    Sales,
    each Date.IsInPreviousNDays([OrderDate], 30)
)
Result
OrderID
OrderDate
1392/10/2026
2402/20/2026
3413/7/2026

Example 2: Flag rows from the past 7 days

Table.AddColumn(
    Sales,
    "Last7Days", each Date.IsInPreviousNDays([OrderDate], 7), type logical
)
Result
OrderID
OrderDate
Last7Days
1403/1/2026FALSE
2413/7/2026TRUE
3423/8/2026FALSE

Example 3: Include today in the past-7-day window

Table.SelectRows(
    Sales,
    each Date.IsInPreviousNDays([OrderDate], 7) or Date.IsInCurrentDay([OrderDate])
)
Result
OrderID
CustomerName
OrderDate
141Diana3/7/2026
242Bob3/8/2026

Compatibility

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