OpenBI Docs Buy

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
ParameterTypeDescription
dateTimeanyA date, datetime or datetimezone value; null gives null.
firstDayOfWeeknullable 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.Monday a 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)
OrderDateWeekend
A-1012024-03-15false
A-1022024-03-16true
A-1032024-03-17true

Date.DayOfWeekName, Date.StartOfWeek, Date.WeekOfYear.

Last updated · OpenBI Studio 0.3.79