Date.DayOfWeek
DateReturns the day of the week for a given date.
Syntax
Date.DayOfWeek(dateTime as any, optional firstDayOfWeek as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | The date, datetime, or datetimezone value to find the day of the week for. |
firstDayOfWeek | number | No | A Day.Type value indicating the first day of the week. Defaults to Day.Sunday (0). Use Day.Monday (1) for ISO weeks. |
Return Value
number — A number from 0 to 6 representing the day of the week.
Remarks
Date.DayOfWeek returns a number from 0 to 6 indicating the day of the week for the given date. By default, 0 represents Sunday and 6 represents Saturday. You can change which day is considered the first day of the week by passing a Day.Type value (e.g., Day.Monday) as the second argument, which shifts the numbering so that the specified day becomes 0. If the input is null, the function returns null.
Examples
Example 1: Find the day of week for each OrderDate
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(Sales, 5),
{"OrderID", "OrderDate"}
),
"DayOfWeek", each Date.DayOfWeek([OrderDate], Day.Sunday), Int64.Type
)Result
OrderID | OrderDate | DayOfWeek | |
|---|---|---|---|
| 1 | 1 | 1/15/2024 | 1 |
| 2 | 2 | 1/18/2024 | 4 |
| 3 | 3 | 2/1/2024 | 4 |
| 4 | 4 | 2/10/2024 | 6 |
| 5 | 5 | 3/5/2024 | 2 |
Example 2: Use Monday as the first day of the week
Table.AddColumn(
Table.SelectColumns(
Table.FirstN(Sales, 4),
{"OrderID", "OrderDate"}
),
"DayOfWeekMon", each Date.DayOfWeek([OrderDate], Day.Monday), Int64.Type
)Result
OrderID | OrderDate | DayOfWeekMon | |
|---|---|---|---|
| 1 | 1 | 1/15/2024 | 0 |
| 2 | 2 | 1/18/2024 | 3 |
| 3 | 3 | 2/1/2024 | 3 |
| 4 | 4 | 2/10/2024 | 5 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks