Date.IsInPreviousNMonths

Updated on

Date.IsInPreviousNMonths is a Power Query M function that indicates whether the given date(time) value occurs during the previous number of months, as determined by the system. The function returns a boolean value (true or false).

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

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

Description

Date.IsInPreviousNMonths determines if dateTime argument (of type date, datetime, or datetimezone) is within a specified number of months before the current system date and time, excluding current month values. It requires a months argument.

Examples

Determine if the month before the current system time is in the previous two months.

// Output: true
Date.IsInPreviousNMonths( Date.AddMonths( DateTime.FixedLocalNow(), -1 ), 2 )

Other functions related to Date.IsInPreviousNMonths are:

BI Gorilla Blog

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/date-isinpreviousnmonths