Date.AddYears Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The Date.AddYears function adds a number of years to a date and gives you the new date. Give it a negative number and it goes back in time instead.

It’s what you use for warranty end dates, license terms, anniversaries, age calculations, and “last 3 years” filters. In this article, I’ll show you how it works, including what happens when you add a year to February 29.

Follow along with the example file

Date.AddYears Function Examples.xlsx

Download

In the example file, each example is its own query. To see the results, go to Data > Queries & Connections and double-click a query to open it in the Power Query editor.

Date.AddYears Function Syntax

Date.AddYears(dateTime as any, numberOfYears as number) as any
  • dateTime – the date, datetime, or datetimezone value you want to add years to.
  • numberOfYears – the number of years to add. Use a negative number to subtract years. It has to be a whole number.

What it returns – a value of the same type you gave it. A date gives you a date, and a datetime gives you a datetime with the same time of day.

If dateTime is null, you get null back instead of an error.

When to Use the Date.AddYears Function

Use this function when you need to:

  • Get the date a few years before or after a date
  • Add an end date column, like a warranty that lasts 2 years
  • Add a different number of years to each row, using a number stored in another column
  • Find this year’s anniversary of a date, like a work anniversary
  • Find the last day of a multi-year term, like a 3-year license
  • Build a list of yearly dates
  • Filter rows to the last few years
  • Calculate someone’s age in completed years

Example 1: Add Years to a Date

Let’s start with the simplest use of the function.

Suppose you have the date May 18, 2026, and you want the date that’s 3 years later.

Create a new blank query (in Excel, go to Data > Get Data > From Other Sources > Blank Query) and type this formula in the formula bar:

= Date.AddYears(#date(2026,5,18),3)

Result: 5/18/2029

Date.AddYears(#date(2026,5,18),3) returns 5/18/2029

Here, #date(2026,5,18) creates the date May 18, 2026, and Date.AddYears moves it 3 years ahead. The month and day stay the same, and only the year changes.

The result shows as 5/18/2029 because my computer uses US regional settings. Power Query shows dates in the order your computer’s regional settings use, so the same date may look different on your screen.

You might think adding 3 times 365 days would do the same job. It doesn’t, because 2028 is a leap year with an extra day, so Date.AddDays(#date(2026,5,18),1095) lands on May 17, 2029, one day short.

Example 2: Subtract Years From a Date

Date.AddYears can also go backward.

Suppose you have the date May 18, 2026, and you want the date 10 years before it.

Create a new blank query (as in Example 1) and use this formula:

= Date.AddYears(#date(2026,5,18),-10)

Result: 5/18/2016

Date.AddYears(#date(2026,5,18),-10) returns 5/18/2016

Here, the -10 tells Date.AddYears to go 10 years back from May 18, 2026. There’s no separate function for subtracting years, so a negative number is how you do it.

Example 3: Add a Warranty End Date Column

In real data, you’ll usually work with a column of dates, not a single date.

Below is a Warranties table with the date each product was bought, and I want the date its 2-year warranty ends in a new Warranty Ends column.

Warranties table with Product ID, Product and Purchase Date

To follow along, select any cell in the Warranties table and go to Data > From Table/Range. Power Query adds a Changed Type step.

Excel dates come into Power Query as date and time values, even when the cell shows only a date.

So click the type icon in the Purchase Date header, pick Date, and choose Replace current. If you skip this, the new dates keep a time part too, so the first warranty end date comes out as 1/9/2028 12:00:00 AM instead of 1/9/2028.

The formula below starts from #"Changed Type", which is the name of that step. So the new column is added to the table after its types are set.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Warranty Ends",each Date.AddYears([Purchase Date],2),type date)

Result: A new Warranty Ends column shows 1/9/2028, 2/27/2028, 4/16/2028, 7/3/2028, and 10/21/2028.

New Warranty Ends column with the date 2 years after each purchase

Here, the Table.AddColumn function adds the Warranty Ends column, and the each keyword runs Date.AddYears on every row. [Purchase Date] picks the date from the same row, and type date makes the new column a Date column.

Every product was bought in 2026, so every warranty ends on the same day and month in 2028. For example, the air fryer bought on 2/27/2026 has a warranty end date of 2/27/2028.

This gives the same date 2 years later. If the warranty covers only up to the day before that, take one day away, as shown in Example 6.

Example 4: Add Years From Another Column

This next one comes up a lot when each row needs a different number of years.

Below is a Certifications table with the date each employee got certified and how many years the certification is valid for, and I want the expiry date in a new Expires On column.

Certifications table with Employee, Certification, Certified On and Valid For (Years)

As in Example 3, load the table with Data > From Table/Range. Make sure the Changed Type step sets Certified On to the Date type and Valid For (Years) to Whole Number.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Expires On",each Date.AddYears([Certified On],[#"Valid For (Years)"]),type date)

Result: A new Expires On column shows 3/10/2027, 6/18/2027, 1/22/2031, 9/5/2026, and 11/14/2027.

New Expires On column using each row's own number of years

Here, the number of years comes from the Valid For (Years) column, so each certification gets its own expiry date. Ricky’s first aid certificate from 3/10/2025 is valid for 2 years, so it expires on 3/10/2027.

The column name has spaces and parentheses in it, so it’s written as [#"Valid For (Years)"]. The #"..." part lets Power Query read a name with special characters.

Important: Date.AddYears only takes whole years. If you pass it a number with decimals, like 1.5, you get the error “The number is out of range of a 32 bit integer value.”

In this example you won’t see that error, because setting Valid For (Years) to Whole Number rounds every decimal first, without any warning. Halves go to the nearest even number, so 1.5 becomes 2 and 2.5 also becomes 2.

So if a validity period can be something like 1.5 years, keep Valid For (Years) as a Decimal Number column instead of Whole Number. Then turn the years into months with the Date.AddMonths function:

= Table.AddColumn(#"Changed Type","Expires On",each Date.AddMonths([Certified On],[#"Valid For (Years)"]*12),type date)

Here, 1.5 years becomes 18 months, so a certificate from 3/10/2025 expires on 9/10/2026. This works as long as the years times 12 is a whole number, because Date.AddMonths also takes only whole months.

A blank number of years gives a different error, “We cannot convert the value null to type Number.” So fill in any blank values before you add the Expires On column.

Example 5: Find This Year’s Work Anniversary

This example shows what Date.AddYears does with a February 29 date, which doesn’t exist in most years.

Below is a Staff table with the date each employee was hired, and I want the date of their work anniversary in 2026 in a new 2026 Anniversary column.

Staff table with Employee and Hire Date

As in Example 3, load the table with Data > From Table/Range, and make sure the Changed Type step sets the Hire Date column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","2026 Anniversary",each Date.AddYears([Hire Date],2026-Date.Year([Hire Date])),type date)

Result: A new 2026 Anniversary column shows 4/13/2026, 9/30/2026, 2/28/2026, 7/8/2026, and 12/4/2026.

New 2026 Anniversary column where the 2/29/2020 hire date lands on 2/28/2026

Here, 2026-Date.Year([Hire Date]) works out how many years to add to get from the hire year to 2026. Owen Bell was hired in 2015, so that’s 11 years, and Date.AddYears moves 4/13/2015 to 4/13/2026.

Miranda Martin was hired on 2/29/2020, and 2026 isn’t a leap year, so there’s no February 29 in 2026.

When the same day doesn’t exist in the new year, Date.AddYears uses the last day of February instead, so her anniversary is 2/28/2026. If your company uses March 1 for leap-day hires instead, you’d need to adjust those rows yourself.

You might try building the date with #date(2026,Date.Month([Hire Date]),Date.Day([Hire Date])) instead. For Miranda, that formula asks for February 29, 2026, which doesn’t exist.

So that row gives the error “The Date operation failed because the resulting value falls outside the range of allowed values.” Date.AddYears avoids that, which is why it’s the better choice here.

To always get the anniversary in the current year, replace the number 2026 in 2026-Date.Year([Hire Date]) with Date.Year(DateTime.LocalNow()). The result then updates when the year changes.

In that case, also change the column name “2026 Anniversary” to a name without the year, like “This Year’s Anniversary”, so it doesn’t go out of date.

Follow along with the example file

Date.AddYears Function Examples.xlsx

Download

Example 6: Get the Last Day of a 3-Year Term

Adding 3 years gives you the same date 3 years later. But for a license that starts on January 1, the last day of the license is December 31, not January 1.

Below is a Licenses table with the date each 3-year software license starts, and I want the last day of each license in a new End Date column.

Licenses table with License ID, Software and Start Date

As in Example 3, load the table with Data > From Table/Range, and make sure the Changed Type step sets the Start Date column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","End Date",each Date.AddDays(Date.AddYears([Start Date],3),-1),type date)

Result: A new End Date column shows 12/31/2028, 2/29/2028, 6/14/2029, 8/31/2029, and 11/19/2029.

New End Date column with the last day of each 3-year license

Here, Date.AddYears first moves each start date 3 years ahead, and then the Date.AddDays function goes back one day. So the license that starts on 1/1/2026 ends on 12/31/2028, which is exactly 3 years of use.

Look at the Design Studio license, which starts on 3/1/2025. Three years later is 3/1/2028, and the day before that is 2/29/2028, because 2028 is a leap year.

Date.AddDays gets that right on its own, so you don’t need to check for leap years yourself.

Example 7: Add Years to a Date and Time

Date.AddYears also works on values that have a time, and the time stays the same.

Below is an Inspections table with the date and time each piece of building equipment was last inspected, and I want the next yearly inspection in a new Next Inspection column.

Inspections table with Equipment and Last Inspection date and time

Load the table with Data > From Table/Range, as in Example 3. This time, keep the Last Inspection column as Date/Time in the Changed Type step, because you want to keep the time.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Next Inspection",each Date.AddYears([Last Inspection],1),type datetime)

Result: A new Next Inspection column shows 1/12/2027 9:00:00 AM, 3/5/2027 1:30:00 PM, 5/21/2027 10:15:00 AM, 8/14/2027 3:45:00 PM, and 10/2/2027 8:30:00 AM.

New Next Inspection column one year later at the same time

Here, Date.AddYears adds one year to each date and keeps the time exactly as it was. So the passenger elevator, last inspected on 1/12/2026 at 9:00 AM, is due again on 1/12/2027 at 9:00 AM.

The new column uses type datetime instead of type date, because the result still has a time in it. A datetimezone value works the same way and keeps its time zone offset too.

Example 8: Create a List of Yearly Dates From February 29

You can also use Date.AddYears to build a list of yearly dates, like the renewal dates of a plan that started on a leap day.

Suppose a plan started on February 29, 2024, and you want that date plus the next four yearly renewal dates.

Create a new blank query (as in Example 1) and use this formula:

= List.Transform({0..4},each Date.AddYears(#date(2024,2,29),_))

Result: A list of 5 dates: 2/29/2024, 2/28/2025, 2/28/2026, 2/28/2027, and 2/29/2028.

A list of five yearly dates starting on 2/29/2024

Here, {0..4} creates the numbers 0 to 4, and the List.Transform function goes through them one at a time. In this formula, _ is the current number, so Date.AddYears adds 0, 1, 2, and so on years to February 29, 2024.

In 2025, 2026, and 2027 there’s no February 29, so those dates land on February 28. But 2028 is a leap year, so the list goes back to 2/29/2028, because every date is worked out from the original date.

This matters because once a date has landed on February 28, anything you add to it starts from February 28. For example, Date.AddYears(Date.AddYears(#date(2024,2,29),1),3) gives 2/28/2028, because the outer Date.AddYears starts from 2/28/2025.

Adding all 4 years to the original date in one go, Date.AddYears(#date(2024,2,29),4), gives 2/29/2028. So always work out each yearly date from the start date, as the List.Transform formula does.

Example 9: Filter Rows to the Last 3 Years

Date.AddYears is also handy inside a filter, where it works out the cutoff date for you.

Below is a Customers table with the date of each customer’s last order, and I want to keep only the customers who ordered in the 3 years up to June 30, 2026.

Customers table with Customer and Last Order

As in Example 3, load the table with Data > From Table/Range, and make sure the Changed Type step sets the Last Order column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.SelectRows(#"Changed Type",each [Last Order] >= Date.AddYears(#date(2026,6,30),-3))

Result: Only three rows are left: Harbor Florists (6/30/2023), Summit Outfitters (2/14/2025), and Riverbend Books (4/3/2026).

Only the three customers with an order on or after 6/30/2023 remain

Here, Date.AddYears(#date(2026,6,30),-3) gives the cutoff date, 6/30/2023. The Table.SelectRows function then keeps the rows where the last order is on or after that date.

Harbor Florists’ last order was on 6/30/2023, the cutoff date itself, and the row stays because of the >= sign. If you use > instead, that row is dropped too.

This filter has no upper limit, so an order dated after June 30, 2026 would also be kept.

To always filter the last 3 years from today, replace #date(2026,6,30) with Date.From(DateTime.LocalNow()), which gives today’s date in Power Query. The filter then moves forward every time you refresh the query.

Example 10: Calculate Age in Completed Years

This last example uses Date.AddYears to work out how old someone is.

Below is a Members table with each member’s birth date, and I want their age on June 30, 2026, in a new Age column.

Members table with Member and Birth Date

As in Example 3, load the table with Data > From Table/Range, and make sure the Changed Type step sets the Birth Date column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Age",each let AsOf = #date(2026,6,30),Years = Date.Year(AsOf) - Date.Year([Birth Date]) in if Date.AddYears([Birth Date],Years) > AsOf then Years - 1 else Years,Int64.Type)

Result: A new Age column shows 38, 30, 26, 46, and 21.

New Age column with each member's age on 6/30/2026

Here, AsOf holds the date you want the age on, June 30, 2026, and Years is the difference between the two years. For Sean Thompson, born on 11/2/1995, that’s 31, but his 2026 birthday on 11/2/2026 comes after June 30.

Date.AddYears gives that birthday, and the if checks whether it’s later than AsOf. If it is, the person hasn’t had their birthday yet, so the formula takes 1 away, and Sean’s age is 30.

You may have seen age worked out as the number of days divided by 365.25. On or right around a birthday, that method can give an age that’s one year too low.

Mallory Phillips turns 26 on 6/30/2026, and Number.RoundDown(Duration.Days(#date(2026,6,30)-[Birth Date])/365.25) gives 25 for her. The Date.AddYears check gives the right answer, 26.

None of these members was born on February 29. For someone who was, Date.AddYears puts the birthday on February 28 in years that have no February 29, so the formula counts them a year older from February 28.

The Int64.Type at the end of the formula makes Age a Whole Number column, the same type you met in Example 4.

To get each member’s age today, replace #date(2026,6,30) with Date.From(DateTime.LocalNow()). Because the date is stored once in AsOf, that’s the only change you need.

If you also need the gap between two dates in days or months, see how to calculate the date difference in Power Query.

Other Excel Articles You May Also Like:

  • Date.Year – Use Date.Year in Power Query M to extract the year from a date.
  • Date.EndOfMonth – Use Date.EndOfMonth in Power Query M to get the last day of a month.
  • Date.Month – Use Date.Month in Power Query M to get the month number from a date.
  • DateTime.LocalNow – Use DateTime.LocalNow in Power Query M to get the current date and time.
  • Duration.Days – Use Duration.Days in Power Query M to extract the day component from a duration value.
  • Date.StartOfMonth – Use Date.StartOfMonth in Power Query M to get the first day of the month.
  • Date.EndOfWeek – Use Date.EndOfWeek in Power Query M to get the last day of a week.
  • List.Dates – Use List.Dates in Power Query M to generate a list of dates.

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.