How to Filter Excel Data for the Last 30 Days Relative to Today
Question details
The user needs to filter a SharePoint-hosted Excel workbook to show records strictly from the last 30 days.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating a dynamic filter for a rolling 30-day date range rather than filtering by a static calendar month.
- Observed behavior
- The user wants an automated or formula-based way to identify and filter rows that fall within the 30-day window relative to the current date.
Ensure your date column contains valid, system-recognized dates rather than plain text, and note that VBA macros are not supported if you are running Excel for the Web in a browser.
Use a Helper Column with the TODAY() Function
Create an extra column with a logical formula that checks if each date falls within the last 30 days, then apply a standard filter.
This is the most reliable method for dynamically filtering rolling dates without needing complex macros or scripts. By utilizing the TODAY() function, the filter automatically shifts forward every day.
Insert a new column next to your data and name the header something descriptive, like 'Last 30 Days'.
In the first data cell of the new column (e.g., B2), type the formula: =AND(A2>=TODAY()-30,A2<=TODAY()). Make sure to replace 'A2' with the cell reference containing your actual date.
Press Enter, then drag the fill handle (the small square at the bottom-right of the cell) down to copy this formula to the rest of your dataset.
Select your column headers, navigate to the 'Data' tab, and click 'Filter'. Click the filter dropdown on your helper column and check only the box for 'TRUE'.

Automate with Office Scripts (For Excel on the Web)
Use Office Scripts to automate the filtering process in a SharePoint-hosted environment where VBA is not supported.
Easily Filter Data by Dynamic Dates with WPS Spreadsheet
WPS Office provides a highly compatible and lightweight spreadsheet tool that flawlessly executes dynamic formulas like TODAY() and AND(), making it effortless to track rolling date ranges.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open the file containing your date records.
- 2. Set Up the Formula: Add a new column next to your dates and enter the formula =AND(A2>=TODAY()-30,A2<=TODAY()).
- 3. Filter the Results: Go to the 'Data' tab, click 'AutoFilter', and filter your new column to display only the 'TRUE' values.

Frequently Asked Questions
Can I filter for the last 7 or 90 days instead of 30?
Yes, simply modify the number in your formula. For example, use =AND(A2>=TODAY()-7,A2<=TODAY()) to filter data from the last 7 days. You can also point the formula to a specific cell that holds your desired number of days.
Why won't my VBA macro work for filtering in SharePoint?
SharePoint opens files using Excel for the Web (the browser version), which does not support executing VBA macros. To automate tasks in the web version, you must use Office Scripts.
How do I filter dates specifically for the previous calendar month?
If you want the strict calendar month (e.g., all of October) rather than a rolling 30-day window, you do not need a formula. Simply click the filter dropdown arrow on your date column header, navigate to 'Date Filters', and select 'Last Month'.




