Sub topic 10
Filtering on text, blanks, and dates
This chapter assumes you can enter formulas in Google Sheets, use open-ended ranges such as A2:C, and read comparison operators (=, <>, >, >=). You should also know how FILTER combines conditions: multiplication or separate arguments for AND, addition for OR.
The earlier chapters filtered on exact matches and numeric thresholds. Real data is messier. Names differ in capitalization, cells are empty, and dates may be stored as text. Each of these makes a FILTER condition behave in ways that surprise people. This chapter covers the three cases and the mistakes that go with them.
The sample data
Every example uses this table in A1:D. Column A is the order date, B is the region, C is the customer, and D is the amount. Some customer cells are empty, and some region values have stray capitalization.
| Order date | Region | Customer | Amount |
|---|---|---|---|
| 2026-01-14 | West | Acme Corp | 1200 |
| 2026-02-03 | east | Birch Ltd | 800 |
| 2026-02-19 | West | (empty) | 450 |
| 2026-03-07 | East | Acme Corp | 2300 |
| 2026-03-22 | North | Cedar Inc | 150 |
Why a condition is just an array of TRUE and FALSE
A FILTER condition such as B2:B="West" is evaluated once per row. It produces a column of TRUE and FALSE values with the same height as the data. FILTER keeps the rows where the value is TRUE. Everything in this chapter is about writing a condition that produces the right TRUE and FALSE values for text, blanks, and dates.
The condition range must have the same number of rows as the data range. If A2:D is the data, then B2:B is a valid condition range and B2:B50 is not, because the heights differ and FILTER returns an error.
Filtering on text
Case sensitivity
In Google Sheets, the = operator compares text without regard to case. "west"="West" is TRUE. This is usually what you want, and it means the east and East rows in the sample data are both matched:
=FILTER(A2:D, B2:B="East")This returns the 2026-02-03 and 2026-03-07 rows. If you do need a case-sensitive match, use EXACT, which compares two values and respects case:
=FILTER(A2:D, EXACT(B2:B, "East"))Here only the 2026-03-07 row is returned. EXACT accepts an array as its first argument inside FILTER, so it is evaluated once per row.
Partial matches with SEARCH
An equality test matches the whole cell. To match part of a cell, use SEARCH, which returns the position of the text you are looking for, or an error if it is absent. Wrap it in ISNUMBER to turn that into TRUE or FALSE:
=FILTER(A2:D, ISNUMBER(SEARCH("corp", C2:C)))This returns every row whose customer contains "corp" anywhere, in any case. SEARCH is case-insensitive. Its case-sensitive sibling is FIND.
Pattern matching with REGEXMATCH
For anything more complex than "contains", use REGEXMATCH. It returns TRUE when a cell matches a regular expression:
=FILTER(A2:D, REGEXMATCH(C2:C, "^(Acme|Birch)"))This keeps rows whose customer starts with "Acme" or "Birch". Two things to remember. REGEXMATCH is case-sensitive unless you add (?i) at the start of the pattern, and it expects text, so it returns an error on a number unless you convert it with TO_TEXT.
Stray spaces
A cell that displays West may actually contain West with a trailing space. The = test treats these as different values and the row silently disappears from the result. Apply TRIM to the condition range to remove leading and trailing spaces:
=FILTER(A2:D, TRIM(B2:B)="West")If a filter drops rows you expected, stray spaces are the first thing to check.
Filtering on blanks
Keeping only non-blank rows
The standard test for "this cell has something in it" is <>"":
=FILTER(A2:D, C2:C<>"")This returns the four rows that have a customer name and drops the 2026-02-19 row.
Keeping only blank rows
Reverse the operator to find the gaps:
=FILTER(A2:D, C2:C="")This is a quick audit formula. It returns exactly the rows with a missing customer, so you can see what needs fixing.
The open-ended range trap
An open-ended range like A2:D extends to the bottom of the sheet, including rows that have no data at all. For those rows, C2:C="" is TRUE, so the blank test above also returns every empty row under your table. In a sheet with 1000 rows and 5 data rows, you would get 995 blank rows back.
The fix is to add a second condition that requires a key column to be filled in. Separate arguments give AND logic:
=FILTER(A2:D, A2:A<>"", C2:C="")Now only rows that have an order date and no customer are returned. Choose a key column that is always filled in for real records, such as an ID or a date.
Empty strings versus truly empty cells
A cell can look empty in two ways. It may contain nothing, or it may contain a formula that returns "". The test C2:C="" treats both as blank. ISBLANK does not: it returns TRUE only for a cell with nothing in it, and FALSE for a formula that returns an empty string. Prefer ="" and <>"" for filtering because they behave consistently in both cases.
Filtering on dates
Dates are numbers
Sheets stores a date as a serial number, the count of days since December 30, 1899. A cell showing 2026-03-07 holds a number, and formatting only changes how it looks. This means comparison operators work on dates as long as the cell really contains a date and not text.
Comparing to a date
Never type a date as a bare string in the comparison. Use DATE(year, month, day), which produces a real date value:
=FILTER(A2:D, A2:A>=DATE(2026,2,1))This returns rows from February 1, 2026 onward. A comparison against the text "2026-02-01" can behave unpredictably, so keep DATE as your habit.
Date ranges
A range with a start and an end uses two conditions. Separate arguments give AND:
=FILTER(A2:D, A2:A>=DATE(2026,2,1), A2:A<=DATE(2026,2,28))This returns the two February rows. For month boundaries it is easier to use an exclusive upper bound, which avoids working out the last day of the month:
=FILTER(A2:D, A2:A>=DATE(2026,2,1), A2:A<DATE(2026,3,1))Relative dates with TODAY
TODAY() returns the current date, so you can build views that move forward on their own. Rows from the last 30 days:
=FILTER(A2:D, A2:A>=TODAY()-30, A2:A<=TODAY())The upper bound excludes future-dated rows. TODAY() recalculates when the sheet recalculates, so the result changes from day to day without any edit.
Filtering by month or year
To match a part of a date, extract it with MONTH or YEAR. Both work on arrays inside FILTER:
=FILTER(A2:D, YEAR(A2:A)=2026, MONTH(A2:A)=3)This returns the March 2026 rows. There is a gotcha with blanks here. An empty cell is treated as the date zero (December 30, 1899), so YEAR of an empty cell returns 1899. That is not equal to 2026, so empty rows are dropped as you would want. Test conditions like YEAR(A2:A)<2000 would wrongly include every empty row, so add A2:A<>"" when you use such a condition.
Dates stored as text
If a date is left-aligned by default and the comparisons return nothing, it is probably text. Imported CSV data often has this problem. Convert it inside the condition with DATEVALUE:
=FILTER(A2:D, DATEVALUE(A2:A)>=DATE(2026,2,1))DATEVALUE errors on an empty cell or on a cell that is already a real date. Because a single error in the condition array makes the whole FILTER fail, wrap the conversion with IFERROR and give blank or invalid values a date that fails the test:
=FILTER(A2:D, IFERROR(DATEVALUE(A2:A), 0)>=DATE(2026,2,1))Rows with unreadable dates convert to 0, which is older than your cutoff, so they are dropped instead of breaking the formula.
Combining text, blank, and date tests
The pieces fit together in one FILTER. This formula returns rows from Q1 2026 for West or East, where the customer is filled in:
=FILTER(A2:D,
A2:A>=DATE(2026,1,1),
A2:A<DATE(2026,4,1),
((TRIM(B2:B)="West")+(TRIM(B2:B)="East"))>0,
C2:C<>"")Each argument after the first is one condition, and every condition must be TRUE for a row to be kept. The OR test on the region is wrapped in parentheses and compared to 0, so that a row matching either region counts as TRUE.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Rows with the right text are missing | Trailing or leading spaces | Use `TRIM(B2:B)="West"` |
| Hundreds of empty rows returned | Blank test on an open-ended range | Add a condition such as `A2:A<>""` |
| Date filter returns `#N/A` | Dates are text, or no row matches | Use `DATEVALUE`, then wrap in `IFERROR` |
| Whole formula returns `#VALUE!` | Condition range height differs from data range | Use the same start row and end row in both |
| `REGEXMATCH` returns an error | The cell holds a number | Wrap the cell in `TO_TEXT` |
Exercises
Exercise
Write a formula that returns all rows of A2:D where the customer in column C contains the word "inc" (in any case) and the amount in column D is greater than 100. Why does a plain equality test not work for the first condition?
Show answer
=FILTER(A2:D, ISNUMBER(SEARCH("inc", C2:C)), D2:D>100). Equality (C2:C="inc") only matches cells whose entire content is "inc", while SEARCH finds the text anywhere in the cell, and ISNUMBER converts the position it returns (or the error when absent) into TRUE or FALSE.
Exercise
Your sheet has 5 data rows in A2:D6 but a formula =FILTER(A2:D, C2:C="") returns about 1000 rows. What is happening, and how do you fix it?
Show answer
The open-ended range A2:D extends to the bottom of the sheet, and every empty row below the data also satisfies C2:C="". Add a condition that requires a real record, for example =FILTER(A2:D, A2:A<>"", C2:C="").
Exercise
Write a formula that returns rows dated in April 2026, where column A may hold dates stored as text, and rows with unreadable dates are ignored instead of causing an error.
Show answer
=FILTER(A2:D, IFERROR(DATEVALUE(A2:A), 0)>=DATE(2026,4,1), IFERROR(DATEVALUE(A2:A), 0)<DATE(2026,5,1)). IFERROR turns unreadable dates into 0, which fails the lower bound, so those rows are dropped.