Date.IsInPreviousNYears Function in Power Query

The Date.IsInPreviousNYears function in Power Query checks whether a given date falls within the previous N years, as determined by the current date and time on the system.

Syntax

Date.IsInPreviousNYears(dateTime as any, years as number) as nullable logical

The function has the following parameters:
• dateTime: A date, datetime, or datetimezone value to be evaluated.
• years: The number of previous years to compare against the current year.

Returns • TRUE if the given dateTime falls within the previous N years from the current year.
• FALSE otherwise.

Example: Checking if a date falls in the last 3 years.

Power Query M

let
    Source = Date.IsInPreviousNYears(#date(2022,2, 26),3)
in
    Source

If the current year is 2025, this will return TRUE because year 2022 is within the previous 3 years (2022, 2023, 2024).

Note: • If the given date is of the current year, then this function returns TRUE.
• The function considers full years, not rolling 365 days.