Date.IsInNextNYears is a Power Query M function that indicates whether the given date(time) value occurs during the next number of years, 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.IsInNextNYears(
dateTime as any,
years as number,
) as nullable logical
Description
Date.IsInNextNYears evaluates if a given value (of type date, datetime, or datetimezone) is within the next specified number of years from the current system date and time, excluding the current year. It includes a years
argument.
Examples
Let’s explore two straightforward examples to understand how the Date.IsInNextNYears function works.
Checking for Dates within the Next N Years
Imagine you have a calendar table and you want to add a column that marks dates as true
if they fall within the next n years. You can do this by using the Date.IsInNextNYears function on your [Date]
column, where n is the number of years to check.
Date.IsInNextNYears( [Date], n ) // Output depends on [Date] column and n
This expression returns true
for any date in the [Date]
column that falls within the next n years.
For example, if today is July 6, 2024, and you set n to 2, this function will return true
for all rows with dates between January 1, 2025, and December 12, 2026. Here’s a screenshot showing this:
You can see that dates within the next 2 years are marked with true
.
Using the Current Date and Time
To test if the year following the current system time falls within the next 3 years, you can use the following expression:
// Output: true
Date.IsInNextNYears( Date.AddYears( DateTime.FixedLocalNow(), 1 ), 3 )
Related functions
Other functions related to Date.IsInNextNYears are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy