Date.EndOfWeek

Updated on

Date.EndOfWeek is a Power Query M function that returns the end of the week, with an optional parameter to set the first day of the week. The function returns the end of the week as a date, datetime, or datetimezone value.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Date.EndOfWeek(
   dateTime as any,
   optional firstDayOfWeek as nullable number,
) as any
ArgumentAttributeDescription
dateTimeA date, datetime or datetimezone value.
firstDayOfWeekoptionalThe Day.Type specifies the starting day of the week. If not explicitly specified, the function defaults to Day.Sunday, aligning with regional week-start norms. It accepts values representing each day:
Day.Sunday (0) for Sunday,
Day.Monday (1) for Monday,
Day.Tuesday (2) for Tuesday,
Day.Wednesday (3) for Wednesday,
Day.Thursday (4) for Thursday,
Day.Friday (5) for Friday,
Day.Saturday (6) for Saturday.

Description

Date.EndOfWeek returns the end of the week for a given date, datetime, or datetimezone value (dateTime). An optional parameter (firstDayOfWeek) can be used to set the first day of the week.By default Day.Sunday is used.

Examples

Get the end of the week for 5/14/2011.

// Output: #date( 2011, 5, 14 )
Date.EndOfWeek( #date( 2011, 5, 14 ) )

Get the end of the week for 5/17/2011 05:00:00 PM -7:00, with Sunday as the first day of the week.

// Output: #datetimezone( 2011, 5, 21, 23, 59, 59.9999999, -7, 0 )
Date.EndOfWeek( #datetimezone( 2011, 5, 17, 5, 0, 0, -7, 0 ), Day.Sunday )

Learn more about Date.EndOfWeek in the following articles:

Other functions related to Date.EndOfWeek are:

BI Gorilla Blog

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/date-endofweek