Date.AddDays is a function in the Power Query M language that adds a specified number of days 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.AddDays(
dateTime as any,
numberOfDays as number,
) as any
Description
The Date.AddDays function allows you to add a specific number of days to a given dateTime argument. This argument can be of type date, datetime, or datetimezone. The function includes a numberOfDays argument, which specifies how many days you want to add (or subtract) to the given dateTime value.
Examples
Adding Days to a Date
Let’s start with a simple example. We want to add 10 days to the date of June 1, 2024. Here’s how we do it:
Date.AddDays( #date( 2024, 6, 1 ), 10 ) // Output: #date( 2024, 6, 11 )
In this example, the Date.AddDays function takes a date value as input and adds 10 days to it. The result is June 11, 2024.
Subtracting Days from a Date
Despite its name, Date.AddDays can also subtract days from a date. Let’s see an example where we subtract 10 days from June 1, 2024:
Date.AddDays( #date( 2024, 6, 1 ), -10 ) // Output: #date( 2024, 5, 22 )
Here, the function shifts the date back to May 22, 2024, by subtracting 10 days.
Adding Days to a DateTime Value
The Date.AddDays function is versatile and can also work with DateTime values. Let’s add 10 days to a specific date and time:
// Output: 6/11/2024, 12:00:00 PM
Date.AddDays( #datetime( 2024, 6, 1, 12, 0, 0 ), 10 )
In this case, the input and output are both DateTime values. The function adds 10 days to June 1, 2024, at 12:00 PM, resulting in June 11, 2024, at the same time.
Adding Days to a DateTimeZone Value
You can even use the Date.AddDays function with DateTimeZone values. Here’s how you can add 10 days to a DateTimeZone value:
// Output: 6/11/2024, 12:00:00 PM +02:00
Date.AddDays( #datetimezone( 2024, 6, 1, 12, 0, 0, 2, 0 ), 10 )
In this example, the function takes a DateTimeZone value as input and adds 10 days to it. The result is June 11, 2024, at 12:00 PM, with the same time zone offset of +02:00.
Related articles
Learn more about Date.AddDays in the following articles:
- Create ISO Week and ISO Year in Power Query M (ISO 8601)
Learn how to create ISO Week and Year numbers in Power Query for consistent weeks and fiscal calendars. Step-by-step tutorial included! » Read more - Return Next Working Day in Power Query
Do you want to return the next working day in Power Query? There is no build in M-function for this, but this post shows how to create one yourself! » Read more
Related functions
Other functions related to Date.AddDays are:
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy