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