Sub topic 10
Filter with the FILTER function
This chapter assumes you can navigate a Google Sheets spreadsheet, enter formulas, and use cell ranges such as A2:D100. It also assumes your source data has one header row and consistent column types.
The FILTER function creates a live result containing only rows that meet one or more conditions. It does not rearrange or delete the source data. When the source changes, the filtered result updates automatically.
Understand the FILTER function
The basic structure is:
=FILTER(range, condition)rangeis the data you want to return.conditionis a range of TRUE or FALSE values with one result for each row.- Rows with TRUE are included.
- Rows with FALSE are omitted.
Suppose your data is in A1:D, with Region in column A and Amount in column C. This formula returns only rows from the West region where the amount is greater than 1000:
=FILTER(A2:D, A2:A="West", C2:C>1000)Each condition is combined with AND. A row must satisfy both conditions. The condition ranges must have the same number of rows as the filtered range. Using A2:A with A2:D is useful because both ranges extend down the sheet together.
Combine conditions
For OR logic, add condition arrays. This formula returns rows from either the West or East region:
=FILTER(A2:D, (A2:A="West")+(A2:A="East"))In Google Sheets, TRUE behaves like 1 and FALSE behaves like 0 in this calculation. A row passes when at least one condition is TRUE.
You can also compare numbers, text, and dates:
=FILTER(A2:D, C2:C>=1000)This returns rows whose Amount is at least 1000. Make sure the values in column C are numbers rather than numbers stored as text. A text value such as "1000" can cause comparisons and sorting to behave unexpectedly.
Handle empty results and output errors
If no row matches, FILTER normally returns #N/A. Use IFERROR to show a useful message:
=IFERROR(FILTER(A2:D, C2:C>=1000), "No matches")The result is an expanding array, sometimes called a spill range. Google Sheets needs empty cells below and beside the formula to display every returned row and column. If another value occupies one of those cells, the result can show #REF!. Move the formula to a clear area or remove the blocking values.
Common errors
- Mismatched ranges:
FILTER(A2:D100, C2:C50>1000)does not provide one condition value for every row. Use matching row boundaries. - Unexpected blanks: Blank cells may pass a condition such as
C2:C<1000. Add a nonblank test when needed. - Wrong data type: Convert text numbers to numbers before filtering. Check for leading apostrophes, currency symbols, or inconsistent formatting.
- Header included as data: Start at row 2 when row 1 contains column headings. Add a header separately if the result needs one.
Exercise
Write a formula that returns rows from A2:D where Region is East and Amount is at least 500. Show "No matches" when no rows qualify.
Show answer
=IFERROR(FILTER(A2:D, A2:A="East", C2:C>=500), "No matches")