Date.IsInPreviousNMonths
DateReturns true if the date falls within the previous N calendar months.
Syntax
Date.IsInPreviousNMonths(dateTime as any, months as number) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A date, datetime, or datetimezone value to test. |
months | number | Yes | The number of months back to include. Must be a positive integer. |
Return Value
logical — true 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)
)OrderID | OrderDate | |
|---|---|---|
| 1 | 35 | 12/10/2025 |
| 2 | 37 | 1/20/2026 |
| 3 | 39 | 2/25/2026 |
Example 2: Flag orders from the past 6 months
Table.AddColumn(
Sales,
"PreviousSixMonths", each Date.IsInPreviousNMonths([OrderDate], 6), type logical
)OrderID | OrderDate | PreviousSixMonths | |
|---|---|---|---|
| 1 | 30 | 8/15/2025 | FALSE |
| 2 | 35 | 12/10/2025 | TRUE |
| 3 | 42 | 3/8/2026 | FALSE |
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)
)OrderID | CustomerName | OrderDate | |
|---|---|---|---|
| 1 | 35 | Diana | 12/10/2025 |
| 2 | 37 | Bob | 1/20/2026 |
| 3 | 39 | Charlie | 2/25/2026 |
| 4 | 42 | Alice | 3/8/2026 |