How to Retrieve the Last Three Years of Data in an Access Query
Question details
The user needs to configure an Access query to successfully display records from the last three years based on a specific date field.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Modifying query criteria to dynamically filter data for the current year and the previous three calendar years.
- Observed behavior
- Attempting to filter dates using the Between operator combined with Boolean expressions returns no records.
Verify that the field you are attempting to filter (e.g., Book Date) is strictly formatted as a Date/Time data type in your table's Design View, as date math functions will fail on text fields.
Filter by Year Using the Date Function in Design View
Replace the 'Between' operator with a dynamic mathematical comparison using the Year() and Date() functions to reliably filter recent records.
Using the Year() function extracts the four-digit year from both your data field and the current system date. By subtracting from the current year, Access can easily determine which records fall into your desired timeframe without complex Boolean logic.
Open your Microsoft Access database, right-click on the query you want to modify in the Navigation Pane, and select 'Design View'.
Find the column containing your target date field (such as [Book Date]) in the query design grid.
In the 'Criteria' row directly underneath your date field, type the following expression: > Year(Date()) - 3
Click the 'Run' button (the red exclamation mark) in the Query Design ribbon to view your filtered results.

Update the Query via SQL View
Directly edit the SQL statement for precise control over the WHERE clause when filtering your date field.
Need a lighter way to analyze data? Try WPS Office
While Microsoft Access is powerful for complex relational databases, many data tracking and filtering tasks can be handled far more easily in a spreadsheet. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office, featuring a robust Spreadsheet tool for straightforward data analysis.
- 1. Install WPS Office: Download and install WPS Office for free from the official website.
- 2. Import Your Data: Export your Access table as an Excel file, then open it directly in WPS Spreadsheet.
- 3. Filter Dates Easily: Use the built-in 'Data Filter' tool in the ribbon to instantly filter records by year, month, or custom date ranges without writing SQL queries.

Frequently Asked Questions
Why does using the Between operator fail in my Access query?
The Between operator requires two distinct, properly formatted date endpoints (e.g., Between #1/1/2020# And #12/31/2023#). If it is combined with complex Boolean logic or dynamically generated date functions without strict formatting, Access may misinterpret the criteria, resulting in syntax errors or zero returned records.
How can I filter an Access query to show data from exactly one year ago?
To filter records starting exactly 365 days prior to the current system date, enter >= Date() - 365 in the Criteria row of your date field. This calculates the exact day rather than relying on the calendar year boundaries.
Can I prompt the user to enter the number of years dynamically?
Yes, you can use a parameter prompt. Enter an expression like > Year(Date()) - [Enter number of years:] in the Criteria row. Whenever the query is run, Access will pop up a dialog box asking the user to input the desired number.




