Others

How to Return the Last Working Day of Each Week with an Access Correlated Subquery

Jason MillerJason Miller Nov 2, 2026 869 views

Question details

The user needs to construct a query in Microsoft Access that correctly filters records to return only the last working day of each week.

How to Return the Last Working Day of Each Week with an Access Correlated Subquery
Product
Microsoft Access
Device & OS
not provided
Scenario
Writing an Access SQL query with a correlated subquery to extract a single maximum date record per calendar week.
Observed behavior
The original query returns incorrect dates or all records in the week because the correlated subquery is not properly constrained to match the outer query's year and week.
Before you start

Ensure you have a working days or calendar table (e.g., WorkDaysCalendar) in your Access database with a valid Date/Time field that can be queried.

Solution 1Recommended

Use a Correlated Subquery with the Format Function

Filter your table by comparing the date of each record to the maximum date found for the matching year and week.

A correlated subquery executes once for every row processed by the outer query. By formatting the dates as 'yyyyww' (Year and Week), you ensure that the subquery searches for the maximum calendar date only within the same week as the current row being evaluated.

1
Open Query Design

Open your Microsoft Access database, navigate to the Create tab on the ribbon, and click Query Design. Close the Show Table dialog.

2
Switch to SQL View

Click the View button on the ribbon (Home or Design tab) and select SQL View from the drop-down menu.

3
Enter the SQL Statement

Input the following correlated subquery: SELECT * FROM WorkDaysCalendar AS C1 WHERE calDate = (SELECT MAX(calDate) FROM WorkDaysCalendar AS C2 WHERE Format(C2.CalDate,"yyyyww",1) = Format(C1.calDate,"yyyyww",1));

4
Run the Query

Click the Run button (red exclamation mark) on the Design tab to execute the query. It will now display only the records corresponding to the last working day of each week.

Use a Correlated Subquery with the Format Function
Syntax Check: Ensure you use Max(CalDate) rather than Max(Close) or other non-date fields, as returning the highest value of an unrelated field will break the date correlation.
Free Microsoft Office alternative

Need a Lightweight Alternative to Microsoft Office?

While Microsoft Access is highly specialized for database management, daily office and data tracking tasks often do not require complex SQL queries. WPS Office provides a free, lightweight, and incredibly intuitive alternative to Microsoft Office. With WPS Spreadsheet, you can easily calculate end-of-week dates using simple Excel-compatible functions instead of writing complex database subqueries.

  1. 1. Download WPS Office: Visit the official WPS Office website to download and install the free suite on your device.
  2. 2. Open WPS Spreadsheet: Launch WPS Spreadsheet and import your working days data directly from an Excel or CSV file.
  3. 3. Use Easy Date Formulas: Use built-in functions like =MAXIFS() to find the latest date in a week without writing complicated correlated subqueries.
Free and lightweight office suite with fast installationFully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx)Built-in advanced date functions (MAX, WEEKNUM, WORKDAY) for easy calculationsFamiliar user interface requiring no steep learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Access subquery return all records in a week instead of just the maximum date?

This happens if your subquery in the WHERE clause lacks the necessary equality check against the outer query. Ensure you are equating the specific date field (e.g., `WHERE calDate = (SELECT MAX(calDate)...)`) rather than just matching the week format.

Can I use DatePart instead of Format for year and week correlation?

Yes, you can use `DatePart("yyyy", calDate)` and `DatePart("ww", calDate)`. However, using `Format(calDate, "yyyyww")` combines both into a single string, resulting in cleaner and often faster SQL syntax.

What does the '1' mean in Format(calDate, "yyyyww", 1)?

The '1' parameter specifies that Sunday is considered the first day of the week. Specifying this parameter prevents incorrect outputs if the system's regional settings vary, ensuring your query behaves consistently.