Smart Systems for Home

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

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

· 5 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.AddWeeks adds a specified number of weeks to a date and returns the resulting date. It is a built-in Power Query function that takes a date, datetime, or datetimezone value and an integer number of weeks, then returns the same type shifted forward (positive number) or backward (negative number). You can use it in a custom column, in the formula bar, or in the Advanced Editor. No add-in or special setup is required beyond having Power Query available in Excel, Power BI, or another Microsoft tool that hosts it.

What You'll Need

  • Excel (any modern version with Power Query), Power BI Desktop, or another host that includes Power Query.
  • A table or query with a date column that is already recognized as a Date, DateTime, or DateTimeZone type.
  • Basic familiarity with the Power Query Editor and the Add Column tab.

Step-by-Step

  1. Load your data into Power Query: select your table and choose Data > From Table/Range (Excel) or Get Data (Power BI). The Power Query Editor opens.
  2. Confirm the date column type. Select the column, then on the Home tab use Data Type and choose Date, Date/Time, or Date/Time/Zone. If the column is Text, Date.AddWeeks will fail until you convert it.
  3. Add a new custom column: go to Add Column > Custom Column. Give it a name such as "Due Date".
  4. In the formula box, enter the function call. The pattern is: Date.AddWeeks([OrderDate], 2) Replace [OrderDate] with your actual column name and 2 with the number of weeks. Use a negative number to subtract weeks, for example Date.AddWeeks([OrderDate], -1).
  5. Click OK. Power Query evaluates the formula for each row and shows the new date column.
  6. Check the new column's data type. It should be Date, Date/Time, or Date/Time/Zone matching the input. If it shows as Any or Text, set the type explicitly using the Data Type dropdown on the Home tab.
  7. Rename the column if needed (double-click the header) and reorder it by dragging.
  8. Load the result: Home > Close & Load (Excel) or Home > Close & Apply (Power BI).

You can also call the function directly in the formula bar or Advanced Editor. For example, to add three weeks to a fixed date: Date.AddWeeks(#date(2024, 1, 15), 3) returns 2024-02-05. The function works on a single value, so inside a table it is used row by row through a custom column or an each expression.

Common Mistakes

  • Passing a text value. If the date column is type Text, Date.AddWeeks returns an error. Convert the column to Date first, or wrap the value with Date.FromText.
  • Forgetting the column reference brackets. In a custom column, column names must be in square brackets, e.g. [OrderDate], not OrderDate.
  • Using a decimal number of weeks. The second argument must be an integer. causes an error; use Date.AddDays for partial weeks.
  • Assuming the result is always a Date. If the input is DateTime, the output is DateTime; if DateTimeZone, the output keeps the zone. Mixing types in later steps can cause comparison errors.
  • Expecting calendar-week logic. Date.AddWeeks adds exactly seven days per week; it does not snap to the start of a week or account for week numbering.

Tips

  • Use a parameter or a column value for the number of weeks to make the step dynamic, e.g. Date.AddWeeks([StartDate], [LeadWeeks]).
  • For month-based offsets, use Date.AddMonths; for business-day logic, combine with Date.DayOfWeek checks.
  • If you need to add weeks to today's date, use Date.AddWeeks(DateTime.LocalNow(), 2) but be aware the result changes each refresh.
  • Keep the original date column and the calculated column separate so you can audit results.
  • Document the step name in the Applied Steps pane so others understand what the offset means.

Troubleshooting

If you see an error such as "We cannot convert the value ... to type Date", the input column likely contains text or nulls. Filter out nulls or convert the column type. If the function name is not recognized, check spelling: it is Date.AddWeeks with a capital D and A, and it is case-sensitive in M. If the custom column dialog rejects the formula, confirm you are using the correct column name exactly as shown in the header, including spaces inside brackets. If the result is off by a day, verify the input date is not a DateTime with a time component that crosses midnight in your locale. If the query is slow, the function itself is not the cause; check upstream steps for row-by-row operations. When a column returns errors only on some rows, use the error list to inspect those rows and correct the source data or add a try/otherwise wrapper: .

Frequently Asked Questions

What is the difference between Date.AddWeeks and Date.AddDays?

Date.AddWeeks adds seven days per unit, while Date.AddDays adds one day per unit. Use AddWeeks for whole-week offsets and AddDays for finer control.

Can I subtract weeks?

Yes. Pass a negative number, for example to go back two weeks.

Does Date.AddWeeks work with DateTimeZone values?

Yes. The function preserves the type, so a DateTimeZone input returns a DateTimeZone shifted by the specified weeks.

Why does my custom column show an error?

The most common causes are a text-typed date column, a missing set of square brackets around the column name, or a non-integer weeks argument.

Can I use a column for the number of weeks?

Yes, as long as that column is a whole number type. For example Date.AddWeeks([StartDate], [WeeksToAdd]) works if [WeeksToAdd] is Int64.Type.

Is Date.AddWeeks available in all Power Query versions?

It is part of the standard M library and is available in current Excel, Power BI Desktop, and Power Query Online. Very old versions may lack it, so update your host application if the function is missing.