Sub topic 5
Turn on a filter and filter by values
A filter hides the rows of a table that don't match what you ask for. It doesn't delete anything and it doesn't reorder the data. This chapter covers creating the filter, filtering by the values in a column, and the behaviors that surprise people.
This chapter assumes you can move around a spreadsheet, enter data, and read ranges such as A1:D100. It also assumes your data is already a single table with one header row, as set up in the first chapter of this tutorial.
The sample table
The examples use this small sales table in A1:D9.
| Region | Rep | Amount | Status |
|---|---|---|---|
| West | Ana | 1200 | Paid |
| East | Ben | 850 | Open |
| West | Cho | 430 | Paid |
| North | Dee | 2100 | Open |
| East | Eli | 990 | Paid |
| West | Fay | 1500 | Open |
| North | Gus | 610 | Paid |
| East | Hal | 1750 | Paid |
Create the filter
- Click any single cell inside the table, for example B4.
- Choose Data > Create a filter. You can also click the funnel icon in the toolbar, or press Ctrl+Shift+L (Cmd+Shift+L on a Mac).
Sheets looks at the cells around your selection and picks the contiguous block of data. It places a small filter icon at the right edge of each cell in the first row of that block, and it treats that row as the header. A thin green border marks the filter range.
You can also select a range yourself before creating the filter, such as A1:D9. Do this when your data has blank rows or columns inside it. A single blank row ends the automatic detection, so the filter would cover only the rows above it.
A sheet has only one basic filter. If you need a different view of the same data, use a filter view (covered in a later chapter) or a formula.
Filter by values
Click the filter icon in the Region header. The menu contains the following:
- Sort options at the top (A to Z and Z to A).
- Filter by condition and Filter by color, which later chapters cover.
- Filter by values, a list of every distinct value in the column, each with a checkbox.
- A search box, plus Select all and Clear links.
All values start checked. To show only West rows:
- Click Clear to uncheck everything.
- Check West.
- Click OK.
Rows 3, 4, 7 and 8 of the original table (the East, North and other non-West rows) disappear. The row numbers on the left turn green and skip numbers, such as 1, 2, 4, 7, 7... in the order the visible rows appear. The icon in the Region header also turns green. Both are your signal that a filter is active.
A shortcut: if you want to hide just one or two values, leave Select all on and uncheck only the values you don't want. If you want to see just one or two, use Clear first and check the ones you want. This is faster than unchecking dozens of values one at a time.
Search in the values list
For a column with many distinct values, type in the search box. The list narrows to values containing your text. Click Select all to check all the search results, then click OK. Be careful here. With a search active, Select all applies to the matching results only, which is usually what you want, but check the list before you confirm.
What the values list shows
- Blank cells appear as (Blanks). Uncheck it to hide rows where that column is empty.
- Dates are grouped in the list, usually by year, then month, then day. You can check a whole month at once.
- Numbers stored as text and real numbers appear as separate entries even when they look the same. If a value appears twice in the list, check the data types (the chapter on data type pitfalls explains how).
- Values that differ only by trailing spaces, such as
WestandWest, appear as two entries. The list is a quick way to spot dirty data.
Filter several columns
Each column keeps its own filter, and Sheets combines them with AND. A row stays visible only if it passes every column's filter.
To see paid West sales, filter Region to West, then open the Status menu and keep only Paid. Only Ana's and Cho's rows remain.
Each column's value list also adapts. Once Region is filtered to West, the Rep list in the Rep menu still shows all reps, but values hidden by other filters are shown greyed or marked so you can see they are excluded. This varies slightly between versions of Sheets, so rely on the visible result rather than the list.
Sort from inside the filter menu
The sort options at the top of each filter menu sort the whole filter range by that column, and the header row stays in place. This works the same as a Data menu sort, but it is limited to the filter range. Unlike a filter, a sort is not undone by removing the filter. The rows stay in their new order. Press Ctrl+Z immediately if you sorted by accident.
Work with the filtered result
Filtering hides rows but changes nothing else, and that has consequences.
- Totals still include hidden rows.
=SUM(C2:C9)adds all eight amounts, filtered or not. To total only the visible rows, use SUBTOTAL:
=SUBTOTAL(109, C2:C9)Function code 109 means SUM. It skips rows hidden by a filter, and it also skips rows you hid by hand. Code 9 also skips filtered-out rows but counts rows you hid manually. Put this formula outside the filter range, or above the header row, so a filter never hides it.
- Copying takes only visible rows. If you select the filtered range and copy it, only the visible rows are copied. This makes a filter a quick way to extract a subset into another sheet.
- Deleting rows removes only visible rows. Select the visible rows, right-click, and choose to delete rows. The hidden rows are not touched. This is useful for removing all rows with a certain value, but check the row numbers afterward.
- Edits don't always re-filter. If you change a value so that a row no longer matches, the row can stay visible until you reapply the filter. Open any filter menu and click OK to apply the criteria again.
Turn off or remove the filter
There are two different actions:
- Data > Remove filter deletes the filter and shows all rows again. The filter settings are lost.
- Clearing a column's checks back to Select all removes the criteria for that column but keeps the filter and its icons in place.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Rows below a blank row are not filtered | Auto-detection stopped at the blank row | Remove the filter, select the whole range, and create it again |
| The header row is filtered like data | The filter range started below the header | Recreate the filter starting from the header row |
| The same value appears twice in the list | Stray spaces, or text versus number | Clean the data with TRIM or convert the type |
| A row you changed is still visible | The filter was not reapplied | Open a filter menu and click OK |
| New rows at the bottom are not filtered | They were added outside the filter range | Remove and recreate the filter, or insert rows inside the range |
Exercise
You filter the sample table so only Region = West is visible. Cell F1 contains =SUM(C2:C9). What does it return, and which formula would return the total of only the visible rows?
Show answer
=SUM(C2:C9) still returns the total of all eight amounts (9,430), because SUM ignores filters. =SUBTOTAL(109, C2:C9) returns only the visible West amounts (1200 + 430 + 1500 = 3130). Place the formula in a cell outside the filtered rows, such as above the header, so the filter does not hide it.
Exercise
You want to see only rows where Status is Paid and Region is East or North. Describe the steps with the basic filter, and say how the two columns are combined.
Show answer
Create the filter on the table. In the Status menu, click Clear, check Paid, and click OK. In the Region menu, click Clear, check East and North, and click OK. Values checked within one column are combined with OR, and the filters on different columns are combined with AND. The result is Eli's and Hal's East rows and Gus's North row.