Smart Systems for Home

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

Power Query Date.DayOfWeek: How to Get Weekday Numbers

· 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

Power Query's Date.DayOfWeek function returns a number from 0 to 6 representing the day of the week for a given date, with 0 typically representing Sunday and 6 representing Saturday. To use it, you need a date column in Power Query and a custom column or transformation step that calls the function. This guide walks through the exact steps, the optional first-day argument, and the common pitfalls that produce off-by-one weekday numbers.

What You'll Need

  • Power BI Desktop, Excel with Power Query (Get & Transform), or another host that includes the Power Query Editor.
  • A table or query containing at least one column of true date values (not text that looks like a date).
  • Basic familiarity with adding a custom column or editing a query step.

Step-by-Step

  1. Open the Power Query Editor. In Excel, select your data and choose Data > From Table/Range. In Power BI Desktop, choose Home > Transform data to open the editor. Menu labels can differ slightly by version, host and region.
  2. Confirm the column is a date type. Select the date column and check the icon in the column header or the Data Type dropdown on the Home tab. If it shows Text or Any, change it to Date. Date.DayOfWeek expects a date value; text will raise an error.
  3. Add a custom column. On the Add Column tab, click Custom Column. Give it a name such as Weekday Number.
  4. Enter the formula. In the formula box type = Date.DayOfWeek([YourDateColumn]), replacing YourDateColumn with the actual column name (use the column list on the right to insert it exactly). Click OK. A new column appears with numbers 0 through 6.
  5. Interpret the result. By default, 0 is Sunday, 1 is Monday, and so on through 6 for Saturday. This default follows the en-US culture. If your report expects Monday as 1, this is already correct; if it expects Monday as 0, see the next step.
  6. Change the first day of the week (optional). The function accepts a second argument: a Day value such as Day.Monday. For example, = Date.DayOfWeek([OrderDate], Day.Monday) returns 0 for Monday and 6 for Sunday. You can also use Day.Sunday, Day.Tuesday, and so on. This is useful when your business week starts on a day other than Sunday.
  7. Convert numbers to names (optional). If you want readable labels, add another custom column with = Date.DayOfWeekName([OrderDate]) for the full name, or use Date.ToText with a format string such as "ddd" for the abbreviated name. Date.DayOfWeekName also accepts an optional culture argument if you need names in another language.
  8. Apply and load. Click Close & Load (Excel) or Close & Apply (Power BI) to bring the new column into your model. If you only need the number for sorting, keep it as a numeric column and hide it from the report view if desired.

Common Mistakes

  • Passing text instead of a date. If the column type is Text, Date.DayOfWeek returns an error. Change the data type first, and check for locale issues if dates were imported in a different format.
  • Assuming Monday is 0. The default first day depends on culture; in en-US it is Sunday. Always test with a known date, such as a recent Monday, to confirm the numbering.
  • Using the wrong column reference. Column names with spaces or special characters must be written exactly as shown in brackets, e.g. [Order Date]. The formula box is case-sensitive for column names in some contexts, so insert from the list.
  • Forgetting the optional argument in shared queries. If you publish a query that relies on the default first day, users in other cultures may see different numbers. Specify Day.Monday or another explicit value to make the result consistent.
  • Expecting a name instead of a number. Date.DayOfWeek returns a number. Use Date.DayOfWeekName for names.

Tips

  • Use Date.DayOfWeek in a conditional column to flag weekends: for example, if the number is 0 or 6, mark it Weekend.
  • When sorting by weekday name, keep the numeric column and use it as the sort-by column in the model; names sort alphabetically otherwise.
  • If you need ISO weekday numbers (Monday = 1 through Sunday = 7), use Date.DayOfWeek(date, Day.Monday) + 1.
  • Test the function on a small sample of dates that include a month boundary and a leap day to confirm behavior.
  • Document the first-day argument in the query step name so other users understand the numbering.

Troubleshooting

If the new column shows errors, check the data type of the source column and look for nulls or blank cells. Date.DayOfWeek returns null for null input, which is expected. If the numbers appear shifted by one, verify the first-day argument and the culture of your Power Query environment; the default can vary. If the formula will not accept the column name, re-insert it from the column list rather than typing it. If the function is not recognized, confirm you are in the Power Query Editor and not in a DAX formula bar; Date.DayOfWeek is a Power Query M function, not a DAX function. For DAX, use WEEKDAY instead. If the query is slow on very large tables, consider adding the weekday number in the source system or using a date dimension table instead of a custom column on a fact table.

Frequently Asked Questions

What does Date.DayOfWeek return?

It returns a number from 0 to 6 representing the day of the week, based on the specified or default first day.

How do I make Monday the first day?

Monday then returns 0.

Can I get the weekday name instead of a number?

Why do I get an error with my date column?

The column is probably typed as Text or contains invalid dates. Change the data type to Date and remove or replace error values.

Is Date.DayOfWeek available in Excel Power Query?

Yes, it is part of the M language available in Excel's Get & Transform and Power BI Desktop. Menu locations may differ slightly.

How do I get ISO weekday numbers (Monday = 1, Sunday = 7)?