Date.IsInPreviousNDays
DateReturns true if the date falls within the previous N days (not including today).
Syntax
Date.IsInPreviousNDays(dateTime as any, days as number) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A date, datetime, or datetimezone value to test. |
days | number | Yes | The number of days back to include. Must be a positive integer. |
Return Value
logical — true 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)
)OrderID | OrderDate | |
|---|---|---|
| 1 | 39 | 2/10/2026 |
| 2 | 40 | 2/20/2026 |
| 3 | 41 | 3/7/2026 |
Example 2: Flag rows from the past 7 days
Table.AddColumn(
Sales,
"Last7Days", each Date.IsInPreviousNDays([OrderDate], 7), type logical
)OrderID | OrderDate | Last7Days | |
|---|---|---|---|
| 1 | 40 | 3/1/2026 | FALSE |
| 2 | 41 | 3/7/2026 | TRUE |
| 3 | 42 | 3/8/2026 | FALSE |
Example 3: Include today in the past-7-day window
Table.SelectRows(
Sales,
each Date.IsInPreviousNDays([OrderDate], 7) or Date.IsInCurrentDay([OrderDate])
)OrderID | CustomerName | OrderDate | |
|---|---|---|---|
| 1 | 41 | Diana | 3/7/2026 |
| 2 | 42 | Bob | 3/8/2026 |