Date.AddQuarters

Updated on

Date.AddQuarters is a function in the Power Query M language that adds a specified number of quarters 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.AddQuarters(
   dateTime as any,
   numberOfQuarters as number,
) as any

Description

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

Examples

Adding Quarters to a Date

Let’s start with a simple example where we add 2 quarters to January 1, 2024. Here’s how to do it:

// Output: #date( 2024, 7, 1 )
Date.AddQuarters( #date( 2024, 1, 1), 2 ) 

In this example, the Date.AddQuarters function takes a date value and adds 2 quarters to it. The result is July 1, 2024.

Subtracting Quarters from a Date

The Date.AddQuarter function can also subtract quarters from a date. Let’s see an example where we subtract 2 quarters from January 1, 2024:

// Output: #date( 2023, 7, 1 )
Date.AddQuarters( #date( 2024, 1, 1), -2 ) 

Here, the function moves the date back to July 1, 2023, by subtracting 2 quarters.

Adding Quarters to a DateTime Value

The Date.AddQuarters function is versatile and can also work with DateTime values. Let’s add 2 quarters to a specific date and time:

// Output: 7/1/2024, 12:00:00 PM
Date.AddQuarters( #datetime( 2024, 1, 1, 12, 0, 0 ), 2 )

In this case, the input and output are both DateTime values. The function adds 2 quarters to January 1, 2024, at 12:00 PM, resulting in July 1, 2024, at the same time.

Adding Quarters to a DateTimeZone Value

You can even use the Date.AddQuarter function with DateTimeZone values. Here’s how you can add 2 quarters to a DateTimeZone value:

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

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

Other functions related to Date.AddQuarters are:

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