HomeGoogle DocsSpreadsheetFilter the Last N Days of Data in Google Sheets

Filter the Last N Days of Data in Google Sheets

The easiest way to filter the last N days of data in Google Sheets is by using the FILTER function in combination with the ISBETWEEN function. Additionally, you may need to use the TODAY and MAX functions, depending on your specific use case.

Below, you will find three formulas, each handling a different scenario. These formulas filter the last N days of data based on:

  1. Today’s date (rolling window approach)
  2. A user-defined date
  3. The maximum date in the dataset

Sample Data

The sample dataset consists of:

  • Column A: Dates
  • Column B: Items (fruit names)
  • Column C: Quantities

The filtering range is A2:C, excluding the header row.

Filter Last N Days from Today (Rolling Window Approach)

The following formula filters the last 7 days of data from today:

=FILTER(A2:C, ISBETWEEN(A2:A, TODAY()-7, TODAY()-1))
Example of filtering the last N days from today

Formula Explanation:

  • A2:C is the range to filter.
  • ISBETWEEN(A2:A, TODAY()-7, TODAY()-1) is the condition.
  • The formula filters rows where the condition is TRUE.
  • The ISBETWEEN function checks if each date in A2:A falls between TODAY()-7 and TODAY()-1.

This formula excludes today’s date. If you want to include today, modify it as follows:

=FILTER(A2:C, ISBETWEEN(A2:A, TODAY()-6, TODAY()))

Filter Last N Days from a Specific Date (User-Defined Date)

The formula above dynamically adjusts based on TODAY(), making it a rolling window approach. However, you might need to filter data relative to a specific date instead.

To do this, replace TODAY() with a user-defined date using the DATE(year, month, day) function. For example, to filter the last 7 days from 12/02/2025:

=FILTER(A2:C, ISBETWEEN(A2:A, DATE(2025, 2, 12)-7, DATE(2025, 2, 12)-1))
Example of filtering the last N days from a specific date

Key Notes:

  • This formula filters data for the last 7 days relative to 12/02/2025.
  • The filtered data excludes 12/02/2025. To include it, modify the formula as follows:
=FILTER(A2:C, ISBETWEEN(A2:A, DATE(2025, 2, 12)-6, DATE(2025, 2, 12)))

This formula is useful for historical data analysis.

Filter Last N Days from the Latest Date in the Data

In cases where your dataset is irregularly updated, you may not have today’s date or a specific reference date. Instead, you can filter data based on the latest date in your dataset using the MAX function.

Here’s how:

=FILTER(A2:C, ISBETWEEN(A2:A, MAX(A2:A)-7, MAX(A2:A)-1))
Example of filtering the last N days from the latest date

Formula Explanation:

  • MAX(A2:A) finds the latest date in column A.
  • The formula then filters the last 7 days from this latest date.

This excludes the latest date. To include it, modify the formula as follows:

=FILTER(A2:C, ISBETWEEN(A2:A, MAX(A2:A)-6, MAX(A2:A)))

This approach is ideal for datasets that are updated at irregular intervals.

Resources

Prashanth K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

How to Build a Road Trip Fuel Cost Splitter Formula in Google Sheets

Need a fair formula to split fuel costs among travelers on a long road...

Road Trip Fuel Cost Splitter in Google Sheets (Free Template)

When you go on a long road trip with friends, splitting fuel expenses fairly...

Savings Tracker Template in Google Sheets (Free Download)

Managing multiple savings goals can become difficult without a proper system to track your...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.