Date.DayOfWeek
Where a day falls in its week, as a number from 0 (the week's first day) to 6.
Group: Dates and times. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Date.DayOfWeek(dateTime as any, optional firstDayOfWeek as nullable number) as nullable number
| Parameter | Type | Description |
|---|---|---|
dateTime | any | A date, datetime or datetimezone value; null gives null. |
firstDayOfWeek | nullable number optional | The day a week starts on: Day.Sunday (0) to Day.Saturday (6). Left out or null, the culture's first day is used. |
Returns
nullable number. 0 for the week's first day up to 6 for its last.
Remarks
- With no first day given, the week starts on the first day of the query's culture: Sunday in en-US, Monday in Norway, Britain and Germany (nb-NO, en-GB, de-DE). Give
Day.Monday(or another day) when the answer must not depend on the culture. - The number counts from the first day you give, so with
Day.Mondaya Monday is 0 and a Sunday 6.
Examples
A Friday in en-US
Date.DayOfWeek(#date(2024, 3, 15))
5
The week starts on Sunday in en-US: Sunday 0, Monday 1 ... Friday 5.
Weeks that start on Monday
Date.DayOfWeek(#date(2024, 3, 15), Day.Monday)
4
Weekend orders
let
Orders = #table({"Order", "Date"}, {{"A-101", #date(2024, 3, 15)}, {"A-102", #date(2024, 3, 16)}, {"A-103", #date(2024, 3, 17)}})
in
Table.AddColumn(Orders, "Weekend", each Date.DayOfWeek([Date], Day.Monday) >= 5, type logical)
| Order | Date | Weekend |
|---|---|---|
| A-101 | 2024-03-15 | false |
| A-102 | 2024-03-16 | true |
| A-103 | 2024-03-17 | true |