Date.IsInPreviousNWeeks
DateReturns true if the date falls within the previous N calendar weeks.
Syntax
Date.IsInPreviousNWeeks(dateTime as any, weeks as number) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A date, datetime, or datetimezone value to test. |
weeks | number | Yes | The number of weeks back to include. Must be a positive integer. |
Return Value
logical — true if the date falls within the N weeks before the current week, false otherwise.
Remarks
Date.IsInPreviousNWeeks returns true if the input date falls within the N complete Sunday–Saturday calendar weeks immediately preceding the current week. The current week is not included; use Date.IsInCurrentWeek to also match the current week. The function is re-evaluated on each query refresh.
Weeks are always Sunday-to-Saturday boundaries. If your organization uses Monday-based weeks, build the filter manually using Date.StartOfWeek and Date.EndOfWeek with Day.Monday.
For a rolling N-day lookback instead of complete weeks, use Date.IsInPreviousNDays(n * 7). Note that Date.IsInPreviousNWeeks(d, 1) is equivalent to Date.IsInPreviousWeek.
Examples
Example 1: Filter orders from the previous 2 weeks
Table.SelectRows(
Sales,
each Date.IsInPreviousNWeeks([OrderDate], 2)
)OrderID | OrderDate | |
|---|---|---|
| 1 | 39 | 2/23/2026 |
| 2 | 40 | 2/26/2026 |
Example 2: Flag orders from the past 4 weeks
Table.AddColumn(
Sales,
"PreviousFourWeeks", each Date.IsInPreviousNWeeks([OrderDate], 4), type logical
)OrderID | OrderDate | PreviousFourWeeks | |
|---|---|---|---|
| 1 | 36 | 2/5/2026 | FALSE |
| 2 | 39 | 2/23/2026 | TRUE |
| 3 | 42 | 3/8/2026 | FALSE |
Example 3: Combine current and previous 4 weeks for a 5-week view
Table.SelectRows(
Sales,
each Date.IsInCurrentWeek([OrderDate]) or Date.IsInPreviousNWeeks([OrderDate], 4)
)OrderID | CustomerName | OrderDate | |
|---|---|---|---|
| 1 | 39 | Charlie | 2/23/2026 |
| 2 | 40 | Alice | 2/26/2026 |
| 3 | 41 | Bob | 3/5/2026 |
| 4 | 42 | Diana | 3/8/2026 |