Date.IsInNextNWeeks

Updated on

Date.IsInNextNWeeks is a Power Query M function that indicates whether the given date(time) value occurs during the next number of weeks, 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.IsInNextNWeeks(
   dateTime as any,
   weeks as number,
) as nullable logical

Description

Date.IsInNextNWeeks evaluates whether a given value (of type date, datetime, or datetimezone) is within the next set number of weeks from the current system date and time, excluding the current week. The function also takes a weeks argument to define the number of weeks.

Examples

Let’s explore two straightforward examples to understand how the Date.IsInNextNWeeks function works.

Checking for Dates within the Next N Weeks

Let’s say you have a calendar table and you want to add a column that shows true for dates within the next n weeks. You can do this using the Date.IsInNextNWeeks function on your [Date] column, where n is the number of weeks you want to check.

Date.IsInNextNWeeks( [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 weeks. If you set n to 2, then you can use the following expression:

Date.IsInNextNWeeks( [Date], 2 )

If today is July 6, 2024, and you set n to 2, this function will return true for all rows with dates between July 8, 2024, and July 21, 2024. Here’s a screenshot showing this:

Example on how to use the Date.IsInNextNWeeks Function in Power Query M

You can see that dates within the next 2 weeks are marked with true.

Using the Current Date and Time

To test if the week following the current system time falls within the next 6 weeks, you can use the following expression:

// Output: true
Date.IsInNextNWeeks( 
  Date.AddWeeks( DateTime.FixedLocalNow(), 1 ), 
  6 
)

Other functions related to Date.IsInNextNWeeks are:

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

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy