Date.IsInPreviousNMonths

Date

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

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

Syntax

Date.IsInPreviousNMonths(dateTime as any, months as number) as logical

Parameters

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

Return Value

logicaltrue if the date falls within the N months before the current month, false otherwise.

Remarks

Date.IsInPreviousNMonths returns true if the input date falls within the N complete calendar months preceding the current month. The current month itself is not included; use Date.IsInCurrentMonth to also match the current month. The function is re-evaluated on each query refresh.

For example, if today is in March and months = 3, it matches any date in December, January, or February. This function counts whole calendar months — it is not a rolling 30-day window. For a rolling day-based lookback, use Date.IsInPreviousNDays with an appropriate number of days.

Use this function for rolling period analysis in financial or sales reporting, such as comparing the trailing 3 months or trailing 12 months against a benchmark period.

Examples

Example 1: Filter orders from the previous 3 months

Table.SelectRows(
    Sales,
    each Date.IsInPreviousNMonths([OrderDate], 3)
)
Result
OrderID
OrderDate
13512/10/2025
2371/20/2026
3392/25/2026

Example 2: Flag orders from the past 6 months

Table.AddColumn(
    Sales,
    "PreviousSixMonths", each Date.IsInPreviousNMonths([OrderDate], 6), type logical
)
Result
OrderID
OrderDate
PreviousSixMonths
1308/15/2025FALSE
23512/10/2025TRUE
3423/8/2026FALSE

Example 3: Combine prior 3 months and current month for a trailing-4-month view

Table.SelectRows(
    Sales,
    each Date.IsInCurrentMonth([OrderDate]) or Date.IsInPreviousNMonths([OrderDate], 3)
)
Result
OrderID
CustomerName
OrderDate
135Diana12/10/2025
237Bob1/20/2026
339Charlie2/25/2026
442Alice3/8/2026

Compatibility

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