How to Filter by Date Range using Query function
To filter by date range using the Query function in Google Sheets, you'll need to use a combination of the "where" clause and the "date" function. Here's a step-by-step guide on how to do it:
- Open your Google Sheets document, and make sure your data has headers, including a date column.
- Click on an empty cell where you want the filtered data to appear.
- Use the Query function in the following format:
=QUERY(data_range, "select * where date_column >= date 'start_date' and date_column <= date 'end_date'", header_row)
data_range
: The range of your data, including headers.date_column
: The letter of the date column in your data.start_date
: The start date of the date range you want to filter (in YYYY-MM-DD format).end_date
: The end date of the date range you want to filter (in YYYY-MM-DD format).header_row
: The row number of your headers.
Example
Let's say you have data in the range A1:D10, with headers in the first row, and the date column is in column A. You want to filter the data to show only records between January 1, 2021, and December 31, 2021. To do this, follow these steps:
- Click on an empty cell, for example, E1.
- Enter the following formula:
=QUERY(A1:D10, "select * where A >= date '2021-01-01' and A <= date '2021-12-31'", 1)
- Press Enter. The filtered data will now appear in columns E to H, showing only records between January 1, 2021, and December 31, 2021.
Did you find this useful?