Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Date.AddMonths: Step-by-Step Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Date.AddMonths adds a whole number of months to a date and returns the resulting date. It is a Power Query M function, so you use it inside a custom column, a query step, or the formula bar, not as a button in the ribbon. The syntax is Date.AddMonths(date, numberOfMonths). The date argument must be a date, datetime, or datetimezone value, and numberOfMonths must be a whole number. Positive numbers move forward, negative numbers move backward, and zero returns the same date. If the target month is shorter than the starting day, Power Query returns the last valid day of that month: adding one month to January 31 gives February 28 (or 29 in a leap year), not March 3. That clamping behavior is the single most important thing to know before you use it.

What You'll Need

  • Power Query available in Excel, Power BI Desktop, or another host that supports M. The steps below use the Power Query Editor, which is the same editor in Excel and Power BI; menu labels can differ slightly by version, device, or region.
  • A query that already contains a column of date values. If the column is text, convert it to Date first with Transform > Data Type > Date.
  • A clear decision about whether you want a new column or a replacement value. Most people want a new column so the original date stays available.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and use Data > From Table/Range. In Power BI Desktop, use Home > Transform data to open the Power Query Editor.
  2. Confirm the date column is typed as Date. Select the column header, then use Transform > Data Type and choose Date. If you see errors after this step, the original values are not valid dates and need cleaning first.
  3. Add a custom column. On the Home tab, choose Add Column > Custom Column. This keeps your original date column intact.
  4. In the Custom Column dialog, give the new column a name, such as RenewalDate or Plus3Months.
  5. Enter the formula in the formula box, replacing the column reference with your own. For example, to add three months to a column named StartDate, type Date.AddMonths([StartDate], 3). Column names are case-sensitive in M and must be wrapped in square brackets.
  6. Click OK. Power Query evaluates the formula for every row and shows the new column. Check a few rows against a calendar before you continue.
  7. If you prefer a single step without the dialog, you can use the formula bar directly. With a step selected in the Applied Steps pane, type a step such as = Table.AddColumn(PreviousStepName, "RenewalDate", each Date.AddMonths([StartDate], 3)). The each keyword tells Power Query to apply the function row by row.
  8. Set the new column's data type to Date. Power Query often infers it, but confirm with Transform > Data Type > Date so later date functions behave correctly.
  9. Rename the step in the Applied Steps pane to something descriptive, such as Added Renewal Date. This makes the query easier to maintain.
  10. Load the query with Home > Close & Load (Excel) or Home > Close & Apply (Power BI).

Common Mistakes

  • Passing text instead of a date. Date.AddMonths expects a date value. If the column is typed as Text, the function returns an error. Convert the type first.
  • Forgetting the square brackets. Writing Date.AddMonths(StartDate, 3) fails because StartDate is not a defined identifier. Use [StartDate].
  • Using a decimal month count. The second argument must be a whole number. Date.AddMonths([StartDate], 1.5) returns an error. Use Date.AddDays for fractional periods.
  • Expecting end-of-month preservation. Adding one month to January 31 returns February 28 or 29, and adding another month from there returns March 28 or 29, not March 31. If you need true month-end behavior, calculate it explicitly rather than chaining Date.AddMonths.
  • Assuming the result includes a time. If the input is a datetime, the time portion is carried through. If you only want the date, wrap the result in Date.From or convert the column type to Date.
  • Editing the wrong step. Changes made in the formula bar apply to the selected step. If the result looks wrong, check which step is highlighted in Applied Steps.

Tips

  • Use negative numbers to go back in time: Date.AddMonths([StartDate], -6) gives the date six months earlier.
  • To add months based on another column, reference that column as the second argument: Date.AddMonths([StartDate], [TermMonths]). Both columns must be whole numbers where required.
  • For a fixed "end of next month" value, combine functions: Date.EndOfMonth(Date.AddMonths([StartDate], 1)). This avoids the clamping surprise.
  • Keep the original date column. It is much easier to audit a query when you can compare the source and the calculated date side by side.
  • Use the formula bar to inspect the generated step. It shows exactly what the Custom Column dialog wrote, which helps when you need to adjust the logic later.
  • If you are building a date table, generate a list of months and apply Date.AddMonths to a start date rather than adding columns row by row.

Troubleshooting

If the new column shows Error in every row, the most likely cause is a type mismatch. Select the source column, confirm it is typed as Date, and check for blank or text values that failed conversion. You can filter those out before adding the custom column.

If only some rows error, those rows probably contain nulls or invalid dates. Date.AddMonths returns null when the date argument is null, so a null result is not the same as an error. An error usually means the value is text or a number that was never converted.

If the formula will not accept your column name, check spelling and capitalization. M is case-sensitive, and the name must match the column header exactly, including spaces inside the brackets.

If the result is off by a day or a month, verify the sign of the second argument and confirm you did not chain two Date.AddMonths steps unintentionally. Also check whether the input column contains a time component that is shifting the displayed value in your host application.

If the step worked but the loaded table shows different values, refresh the query. In Excel, use Data > Refresh All. In Power BI, use Home > Refresh. If the error persists after a refresh, open the Query Editor and inspect the step directly rather than the loaded output.

Frequently Asked Questions

What does Date.AddMonths return for January 31 plus one month?

It returns February 28 in a common year and February 29 in a leap year. Power Query clamps to the last valid day of the target month.

Can I add months to a datetime value?

Yes. The date portion shifts by the number of months, and the time portion is preserved. Convert the result to Date if you only need the date.

Why does my formula return an error instead of a date?

The most common reasons are a text-typed column, a missing set of square brackets around the column name, or a non-whole number in the second argument.

How do I subtract months?

Use a negative number: Date.AddMonths([StartDate], -3) returns the date three months earlier.

Does Date.AddMonths work in Excel and Power BI the same way?

Yes. It is part of the M language used by the Power Query engine in both, so the function behaves identically. Only the surrounding menus differ.

Can I use a column for the number of months?

Yes, as long as that column contains whole numbers. Reference it in the second argument, for example Date.AddMonths([StartDate], [TermMonths]).