Date.IsInPreviousNWeeks

Date

Returns true if the date falls within the previous N calendar weeks.

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

Syntax

Date.IsInPreviousNWeeks(dateTime as any, weeks as number) as logical

Parameters

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

Return Value

logicaltrue 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)
)
Result
OrderID
OrderDate
1392/23/2026
2402/26/2026

Example 2: Flag orders from the past 4 weeks

Table.AddColumn(
    Sales,
    "PreviousFourWeeks", each Date.IsInPreviousNWeeks([OrderDate], 4), type logical
)
Result
OrderID
OrderDate
PreviousFourWeeks
1362/5/2026FALSE
2392/23/2026TRUE
3423/8/2026FALSE

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)
)
Result
OrderID
CustomerName
OrderDate
139Charlie2/23/2026
240Alice2/26/2026
341Bob3/5/2026
442Diana3/8/2026

Compatibility

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