Date.AddWeeks

Updated on

Date.AddWeeks is a function in the Power Query M language that adds a specified number of weeks to a date or datetime value. The resulting value is returned as a date, datetime, or datetimezone.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Date.AddWeeks(
   dateTime as any,
   numberOfWeeks as number,
) as any

Description

The Date.AddWeeks function allows you to add a specific number of weeks to a given dateTime argument. This argument can be of type date, datetime, or datetimezone. The function includes a numberOfWeeks argument, which specifies how many weeks you want to add (or subtract) to the given dateTime value.

Examples

Adding Weeks to a Date

Let’s start with a simple example where we add 3 weeks to a date. Suppose we have January 1, 2024, and we want to add 3 weeks to this date. Here’s how to do it:

// Output: #date( 2024, 1, 22 )
Date.AddWeeks( #date( 2024, 1, 1), 3 )

In this example, the Date.AddWeeks function takes January 1, 2024, and adds 3 weeks to it. The result is January 22, 2024.

Subtracting Weeks from a Date

The Date.AddWeeks function can also subtract weeks from a date. For instance, let’s subtract 2 weeks from January 15, 2024:

// Output: #date( 2024, 1, 1 )
Date.AddWeeks( #date( 2024, 1, 15), -2 )

Here, the function moves the date back by 2 weeks, resulting in January 1, 2024.

Adding Weeks to a DateTime Value

The Date.AddWeeks function also works with DateTime values. Let’s add 4 weeks to a specific date and time:

// Output: 1/29/2024, 10:00:00 AM
Date.AddWeeks( #datetime( 2024, 1, 1, 10, 0, 0 ), 4 )

In this case, the function takes a DateTime value of January 1, 2024, at 10:00 AM and adds 4 weeks to it, resulting in January 29, 2024, at the same time.

Subtracting Weeks from a DateTime Value

You can also subtract weeks from a DateTime value. For example, let’s subtract 1 week from January 10, 2024, at 3:00 PM:

// Output: 1/3/2024, 3:00:00 PM
Date.AddWeeks( #datetime( 2024, 1, 10, 15, 0, 0 ), -1 )

Here, the function moves the DateTime value back by 1 week, resulting in January 3, 2024, at 3:00 PM.

Adding Weeks to a DateTimeZone Value

The Date.AddWeeks function is also capable of working with DateTimeZone values. Let’s add 2 weeks to a DateTimeZone value:

// Output: 1/15/2024, 12:00:00 PM +02:00
Date.AddWeeks( #datetimezone( 2024, 1, 1, 12, 0, 0, 2, 0 ), 2 )

In this example, the function takes a DateTimeZone value of January 1, 2024, at 12:00 PM with a +02:00 time zone offset, and adds 2 weeks to it. The result is January 15, 2024, at 12:00 PM with the same time zone offset.

Other functions related to Date.AddWeeks are:

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

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