Date.EndOfWeek Function in Power Query M

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The Date.EndOfWeek function gives you the last day of the week for any date. You’d use it for week-ending dates on timesheets, weekly pay periods, and weekly totals.

The thing to watch is which day your week ends on. By default, Power Query treats Sunday as the first day of the week, so the week ends on Saturday.

If your weeks start on a different day, the function has an optional setting for that.

In this article, I’ll show you how that works, what happens with a date and time, and the most common ways to use the function.

Follow along with the example file

Date.EndOfWeek Function Examples.xlsx

Download

Date.EndOfWeek Function Syntax

Date.EndOfWeek(dateTime as any, optional firstDayOfWeek as nullable number) as any
  • dateTime – the date, datetime, or datetimezone value you want the end of the week for.
  • firstDayOfWeek (optional) – the day your week starts on, such as Day.Sunday, Day.Monday, or Day.Saturday. If you leave it out, it’s Day.Sunday.

What it returns – the last moment of the week that contains dateTime, as the same type you gave it.

For a date, that’s simply the last day of the week. For a datetime or datetimezone, it’s the last day of the week at 11:59:59.9999999 PM, and a datetimezone keeps its time zone offset.

The last day of the week is always the day before firstDayOfWeek, so with Day.Monday, the week ends on Sunday.

If dateTime is null, you get null back instead of an error.

When to Use the Date.EndOfWeek Function

Use this function when you need to:

  • Get the last day of the week for a date
  • Add a week-ending date column to a table, like on a timesheet
  • Work with weeks that start on Monday or end on Friday
  • Find the end of next week for a due date
  • Total values by week, with the week-ending date as the label
  • Keep all the rows up to the end of a week, including the last day’s evening entries
  • Build a list of week-ending dates for a quarter

Example 1: Get the Last Day of the Week for a Date

Let’s start with the simplest use of the function.

Suppose you have the date April 15, 2026 (a Wednesday), and you want the last day of that week.

Create a new blank query (in Excel, go to Data > Get Data > From Other Sources > Blank Query) and type this formula in the formula bar:

= Date.EndOfWeek(#date(2026,4,15))

Result: 4/18/2026

Date.EndOfWeek(#date(2026,4,15)) returns 4/18/2026, a Saturday

Here, #date(2026,4,15) creates the date April 15, 2026, and Date.EndOfWeek returns Saturday, April 18, 2026.

Since I didn’t give it a second argument, the week starts on Sunday (April 12) and ends on Saturday (April 18).

The date shows as 4/18/2026 because my computer uses US regional settings. On a computer set to UK settings, the same value shows as 18/04/2026, but it’s still the same date.

If the date is already a Saturday, you get the same date back. And a date near the end of December can return a date in the next year, like 12/30/2026 giving 1/2/2027.

Example 2: Get the End of a Week That Starts on Monday

A lot of businesses don’t run their weeks from Sunday to Saturday. If your weeks start on Monday, you need the second argument.

Suppose you have the same date, April 15, 2026, but your weeks run from Monday to Sunday.

Create a new blank query (as in Example 1) and use this formula:

= Date.EndOfWeek(#date(2026,4,15),Day.Monday)

Result: 4/19/2026

With Day.Monday, Date.EndOfWeek returns 4/19/2026, a Sunday

Here, Day.Monday tells the function that the week starts on Monday (April 13), so the week ends on Sunday, April 19, 2026.

That’s one day later than Example 1 for the exact same date. So always check which day your weeks start on before you use this function.

Day.Monday is just the number 1 (and Day.Sunday is 0), so Date.EndOfWeek(#date(2026,4,15),1) gives the same result. I’d still use Day.Monday because it’s easier to read.

If you want the first day of the week instead, use the Date.StartOfWeek function. It takes the same arguments, and with Day.Monday it returns Monday, 4/13/2026.

Example 3: Use Date.EndOfWeek With a Date and Time

This is where most of the surprises with Date.EndOfWeek come from.

Suppose you have a date and time, April 15, 2026 at 9:30 AM, and you want the end of that week.

Create a new blank query (as in Example 1) and use this formula:

= Date.EndOfWeek(#datetime(2026,4,15,9,30,0))

Result: 2026-04-18T23:59:59.9999999

With a datetime input, Date.EndOfWeek returns 2026-04-18T23:59:59.9999999, the last moment of Saturday

Here, #datetime(2026,4,15,9,30,0) creates April 15, 2026 at 9:30 AM. Since the input has a time, Date.EndOfWeek returns a datetime too, set to the very last moment of Saturday, April 18.

Power Query shows this single value in a year-month-day form with the full time. 23:59:59.9999999 is 11:59:59.9999999 PM, a fraction of a second before Sunday starts.

So anything that happens on Saturday, even at 11:58 PM, still counts as before the end of the week. You’ll use this in Example 8.

Note that this result is not equal to the date 4/18/2026. For example, Saturday, April 18 at 12:00 AM doesn’t match 11:59:59 PM, so an equality check against it returns FALSE.

When your dates come from a table column and you want plain dates back, set that column to the Date type first (as you’ll see in Example 4).

Example 4: Add a Week Ending Column to a Table

In real data, you’ll usually want the week-ending date for a whole column of dates.

Below is a Timesheet table with the date of each work entry, and I want the Sunday that ends each entry’s Monday-to-Sunday week in a new Week Ending column.

Timesheet table with Entry, Employee, Work Date and Hours

To follow along, select any cell in the Timesheet table and go to Data > From Table/Range. Power Query adds a Changed Type step, and Excel dates usually come in there with the Date/Time type.

If you leave the column as Date/Time, Date.EndOfWeek returns a date and time (11:59:59 PM on the last day, as in Example 3), not a plain date. So click the type icon in the Work Date header, pick Date, and choose Replace current.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Week Ending",each Date.EndOfWeek([Work Date],Day.Monday),type date)

Result: A new Week Ending column shows 4/12/2026, 4/12/2026, 4/12/2026, 4/19/2026, and 4/19/2026.

New Week Ending column with the Sunday that ends each Monday-to-Sunday week

Here, the Table.AddColumn function adds the Week Ending column, and the each keyword runs Date.EndOfWeek on every row. [Work Date] picks the date from the same row, and type date makes the new column a Date column.

The first argument, #"Changed Type", is the name of the Changed Type step you just set up. So the new column is added to the table as it looks after that step.

Wendy’s entry on Sunday, 4/12/2026 is already the last day of its week, so it gets the same date. Kendra’s entry on Monday, 4/13/2026 starts a new week, so it gets 4/19/2026.

Example 5: Get a Week That Ends on Friday

Here’s another common use case. Some weeks don’t end on a weekend at all, like a weekly pay period that closes every Friday.

Below is a DriverShifts table with the date of each delivery shift, and I want the Friday that closes each shift’s pay period in a new Pay Period End column.

DriverShifts table with Shift, Driver and Shift Date

As in Example 4, load the table with Data > From Table/Range, and make sure the Changed Type step sets the Shift Date column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Pay Period End",each Date.EndOfWeek([Shift Date],Day.Saturday),type date)

Result: A new Pay Period End column shows 4/10/2026, 4/17/2026, 4/17/2026, 4/17/2026, and 4/24/2026.

New Pay Period End column with the Friday that closes each pay period

Here, Day.Saturday makes each week run from Saturday to Friday. So the last day of every week is a Friday.

Note that you don’t pass the day you want the week to end on. You pass the day after it, which is the first day of the week.

Timothy’s shift on Friday, 4/10/2026 is already the end of its pay period. Mitchell’s shift on Saturday, 4/11/2026 starts a new pay period, so it gets the next Friday, 4/17/2026.

Follow along with the example file

Date.EndOfWeek Function Examples.xlsx

Download

Example 6: Find the End of Next Week

Date.EndOfWeek works well with the Date.AddDays function when a deadline falls at the end of a later week.

Below is a RepairRequests table with the date each tenant asked for a repair, and I want a Fix By date in a new column. The rule is that a repair must be done by the end of the following Monday-to-Sunday week.

RepairRequests table with Request, Tenant and Request Date

As in Example 4, load the table with Data > From Table/Range, and make sure the Changed Type step sets the Request Date column to the Date type.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Fix By",each Date.EndOfWeek(Date.AddDays([Request Date],7),Day.Monday),type date)

Result: A new Fix By column shows 4/19/2026, 4/19/2026, 4/19/2026, 4/26/2026, and 5/3/2026.

New Fix By column with the Sunday that ends the following week

Here, the Date.AddDays function first moves the request date seven days ahead, which always lands in the next week. Then Date.EndOfWeek takes that new date to the Sunday that ends its week.

So Karen’s request on Monday, 4/6/2026 moves to 4/13/2026 first, and then to Sunday, 4/19/2026. Kristen’s request on 4/22/2026 gets 5/3/2026, which crosses into May.

Justin asked on Sunday, 4/12/2026, the last day of a week, so he also gets 4/19/2026. That gives him only seven days, while Karen gets almost two weeks.

Example 7: Total Values by Week Ending

Now let’s use the week-ending date to add up a table by week.

Below is an Orders table with the date and amount of each order, and I want the total sales for each Monday-to-Sunday week, labeled with the week-ending date.

Orders table with Order, Sales Rep, Order Date and Amount

As in Example 4, load the table with Data > From Table/Range. Make sure the Changed Type step sets the Order Date column to the Date type and the Amount column to Decimal Number.

First, add a week-ending date for each order. Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.AddColumn(#"Changed Type","Week Ending",each Date.EndOfWeek([Order Date],Day.Monday),type date)

Power Query names a step added this way Custom1, so right-click it in the Applied Steps pane, choose Rename, and call it Added Week Ending. The next formula refers to it by that name.

Next, group the orders by that week-ending date. Add another new step and use this formula:

= Table.Group(#"Added Week Ending",{"Week Ending"},{{"Total Sales",each List.Sum([Amount]),type number}})

Result: Three rows: 4/12/2026 with 1195, 4/19/2026 with 885, and 4/26/2026 with 625.

Total sales for each week, labeled with the week-ending date

Here, the first step gives every order in the same week the same week-ending date. The Table.Group function then makes one row for each week-ending date, and the List.Sum function adds up the amounts in that group.

So the four orders from 4/6/2026 to 4/12/2026 (320, 275, 410, and 190) become one row for 4/12/2026 with 1195.

A week-ending date works well as a week label because it’s a real date. It sorts in the right order and tells you exactly which week it is, unlike a week number such as “Week 15”.

Example 8: Keep All Rows Up to the End of a Week

This is where the 11:59:59 PM time from Example 3 helps you.

Below is a Registrations table with the date and time each attendee registered for an event, and I want to keep only the registrations made up to the end of the week of April 15, 2026 (a Monday-to-Sunday week).

Registrations table with Registration, Attendee and Registered At

As in Example 4, load the table with Data > From Table/Range. This time, keep the Registered At column as Date/Time, because the time of each registration matters here.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:

= Table.SelectRows(#"Changed Type",each [Registered At]<=Date.EndOfWeek(#datetime(2026,4,15,0,0,0),Day.Monday))

Result: Only three rows are left: WR-501 (4/14/2026 10:20:00 AM), WR-502 (4/17/2026 3:45:00 PM), and WR-503 (4/19/2026 11:50:00 PM).

Only the three registrations made up to 4/19/2026 11:59:59 PM remain

Here, Date.EndOfWeek(#datetime(2026,4,15,0,0,0),Day.Monday) gives the last moment of Sunday, April 19, 2026 (11:59:59.9999999 PM). The Table.SelectRows function keeps only the registrations made on or before that moment.

The input is a #datetime, not a #date, so the result is that 11:59:59 PM datetime, which is what gets compared with each time in the Registered At column.

Hannah’s registration at 11:50 PM on Sunday stays in, because it’s before 11:59:59 PM. Blake’s registration at 12:05 AM on Monday, April 20 is dropped.

If you compared with #datetime(2026,4,19,0,0,0) instead, you’d lose every registration made during Sunday itself. Date.EndOfWeek avoids that because it covers the whole last day.

To use a different week, change the #datetime inside Date.EndOfWeek to any day in that week, and keep it a datetime.

If you want the current week, you can use today’s date instead. Here’s how to get today’s date in Power Query.

Example 9: Create a List of Week-Ending Dates

This last example builds the week-ending dates for a whole quarter, which is handy for a weekly reporting calendar.

Suppose you want every Sunday that ends a Monday-to-Sunday week in April, May, and June 2026.

Create a new blank query (as in Example 1) and use this formula:

= List.Dates(Date.EndOfWeek(#date(2026,4,1),Day.Monday),13,#duration(7,0,0,0))

Result: A list of 13 dates from 4/5/2026 to 6/28/2026.

A list of the 13 week-ending Sundays from 4/5/2026 to 6/28/2026

Here, Date.EndOfWeek(#date(2026,4,1),Day.Monday) gives the end of the week that contains April 1, which is Sunday, 4/5/2026. That’s the first date in the list.

The List.Dates function then starts from that date and creates 13 dates, each seven days apart, because #duration(7,0,0,0) is a step of seven days.

The week that contains June 30 ends on 7/5/2026, so it isn’t in this list. If you want more or fewer weeks, change the 13 in the formula.

To turn the list into a table you can load to a sheet, click To Table on the List Tools Transform tab.

Other Excel Articles You May Also Like:

All Power Query Functions

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.