Date.IsInPreviousNMonths Function in Power Query
The Date.IsInPreviousNMonths function indicates whether the given datetime value occurs during the previous number of whole months, as determined by the current date and time on the system.
Syntax
Date.IsInPreviousNMonths( dateTime as any, months as number ) as nullable logical
The function has the following parameters:
- dateTime: A
date
,datetime
, ordatetimezone
value to be evaluated. - months: The number of months.
Returns:
- TRUE if dateTime falls within the previous N full months.
- FALSE otherwise.
Example: Check if the given date lies in the last 3 months, assuming the current date is 24 Aug 2025.
Power Query M
let Source = Date.IsInPreviousNMonths(#date(2025, 5, 15), 3) in Source
The output of the above code is a logical value true.
Note: • For the current month datetime values the function returns false.
• It only considers full months, not rolling 30/60/90 days.
• The comparison is based on the system’s current date.