Smart Systems for Home

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

Power Query Date.StartOfWeek: How to Use It

· 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

The Date.StartOfWeek function in Power Query returns the date of the first day of the week for any given date. By default it treats Sunday as the start of the week, but you can change that by supplying an optional second argument. You do not need any special setup: open the Power Query Editor, add a custom column, and call the function. The shortest working version is Date.StartOfWeek([OrderDate]), which returns the Sunday on or before each date in the column.

What You'll Need

  • Power Query available in Excel (Data > Get & Transform Data) or Power BI Desktop (Transform data). Menu labels can differ slightly by version, device or region.
  • A table or query with at least one column of true date values. Text that looks like a date will not work until it is converted with Date.From or changed to a Date type.
  • A basic understanding of adding a custom column in the Power Query Editor.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > Get & Transform Data > From Table/Range. In Power BI Desktop, use Home > Transform data to open the Power Query Editor.
  2. Check the date column type. Select the column header; if the icon shows ABC or a number, go to Transform > Data Type and choose Date. This step is essential because Date.StartOfWeek expects a date value, not text.
  3. Add a new custom column. On the Add Column tab, click Custom Column. Give it a name such as Week Start.
  4. Enter the formula in the box. For a column named OrderDate, type Date.StartOfWeek([OrderDate]). The square brackets refer to the column name, not to a cell reference.
  5. Click OK. Power Query adds the new column. Each row now shows the Sunday on or before that row's date.
  6. To start the week on Monday instead, use the optional second argument: Date.StartOfWeek([OrderDate], Day.Monday). Other valid values include Day.Tuesday through Day.Saturday. Day.Sunday is the default.
  7. Set the new column's data type to Date if it is not already. Select the new column header and choose Date from the Data Type menu.
  8. Rename the column if needed by double-clicking its header, then click Close & Load (Excel) or Close & Apply (Power BI) to load the result.

Common Mistakes

  • Passing text instead of a date. If the source column is typed as text, the function returns an error. Convert the column to Date first, or wrap it: Date.StartOfWeek(Date.From([OrderDate])).
  • Forgetting the optional argument. Many users expect Monday to be the default. It is not; Sunday is. Add Day.Monday explicitly if your business week starts on Monday.
  • Using a quoted day name. Date.StartOfWeek([OrderDate], "Monday") fails. The second argument must be a Day constant such as Day.Monday, not a string.
  • Confusing it with Date.StartOfMonth. Date.StartOfWeek returns a date, not a week number. If you need a week number, use Date.WeekOfYear instead.
  • Column name typos. The bracketed name must match the column header exactly, including spaces. A mismatch produces an error in every row.

Tips

  • Use consistently across reports so weekly totals line up with how your team actually works.
  • Combine it with Date.EndOfWeek to build a week range: start date in one column, end date in another.
  • If you need the week start as text for labels, wrap the result: .
  • Apply the function in a custom column rather than editing the source column, so the original date stays available for other calculations.
  • For large tables, set the column type once after adding the custom column; repeated type changes slow refresh.

Troubleshooting

If every row shows an error, check the column type first. A text column is the most common cause; change it to Date and refresh the preview. If only some rows error, those rows likely contain blanks or invalid dates. Filter them out or handle them with try ... otherwise null, for example try Date.StartOfWeek([OrderDate]) otherwise null.

If the result looks like a number such as 45291, the column type is set to Whole Number. Change it to Date to display it properly. If the week appears to start on the wrong day, confirm whether you supplied Day.Monday; without it, Sunday is used.

If the custom column dialog rejects the formula, check for a missing closing parenthesis or a misspelled column name. Power Query is case-sensitive for function names in some contexts, so type Date.StartOfWeek exactly. If the function is not recognized at all, make sure you are in the Power Query Editor and not in a regular Excel formula bar; Date.StartOfWeek is a Power Query (M) function, not an Excel worksheet function.

Frequently Asked Questions

What does Date.StartOfWeek return by default?

It returns the date of the Sunday on or before the given date, because Sunday is the default start of the week.

How do I make Monday the first day of the week?

Add the second argument: . Use Day.Tuesday through Day.Saturday for other start days.

Why does my formula return an error?

The most common reasons are a text-typed date column, a misspelled column name, or a quoted day name instead of a Day constant. Convert the column to Date and use Day.Monday, not "Monday".

Can I use Date.StartOfWeek in a calculated column in Power BI?

Yes, inside the Power Query Editor as a custom column. It is an M function, so it does not work in DAX calculated columns; use the DAX equivalent there instead.

Does it work with blank dates?

No. Blank or null values cause an error unless you handle them with try ... otherwise null or filter them out first.

What is the difference between Date.StartOfWeek and Date.WeekOfYear?

Date.StartOfWeek returns a date (the first day of that week). Date.WeekOfYear returns a number representing the week's position in the year.