Sub topic 11
Driving a Filtered View from Input Cells
Assume you know how to enter formulas, use cell references, and compare values with operators such as = and >=. This chapter uses a table with headers in row 1:
| A | B | C |
|---|---|---|
| Product | Region | Sales |
| Laptop | West | 1800 |
| Monitor | East | 900 |
| Keyboard | West | 250 |
Suppose cell F1 contains a region name. You can use that cell as criteria for a self-updating report.
Use an input cell as the filter
Place this formula in an empty area, such as H2:
=FILTER(A2:C, B2:B=F1)The formula returns every row whose Region value equals the value in F1. If you change F1 from West to East, the result updates automatically.
The first argument, A2:C, is the data to return. The second argument, B2:B=F1, creates one TRUE or FALSE value for each row. FILTER keeps rows with TRUE.
Leave enough empty space below and beside H2. The result spills into those cells. A spill is the automatic placement of an array result across multiple rows or columns.
Add an “all” option
A blank input can mean “show every region.” Use addition to combine two alternatives:
=FILTER(A2:C, (F1="")+(B2:B=F1))When F1 is blank, F1="" is TRUE for every row, so every row passes. When F1 contains West, only rows where B2:B=F1 are included.
You can also use a label such as All:
=FILTER(A2:C, (F1="All")+(B2:B=F1))The value in F1 must match the label exactly, including spaces.
Create a dropdown for safer input
A dropdown prevents spelling differences such as West, west, and Wset.
- Select
F1. - Open Data, then Data validation.
- Add dropdown values such as
All,East, andWest. - Select a value and check that the filtered result changes.
A dropdown is useful when other people will use the sheet. It also makes the available choices visible.
> callout tip > Keep the criteria cell separate from the output range. If the filtered result spills into the criteria cell, the formula can become confusing or create a circular reference. > ```
Add a second input condition
Suppose F2 contains a minimum sales amount. This formula requires both conditions:
=FILTER(A2:C, (F1="All")+(B2:B=F1), C2:C>=F2)The separate condition arguments use AND logic. A row must satisfy the region test and have sales at least equal to F2.
If the “all regions” option is blank instead of All, use this version:
=FILTER(A2:C, (F1="")+(B2:B=F1), C2:C>=F2)Keep the ranges aligned. A2:C, B2:B, and C2:C must describe the same rows. A condition with a different height can produce an error or incorrect results.
Check the result
Test the view with these inputs:
| F1 | F2 | Expected result |
|---|---|---|
| West | 1000 | Laptop |
| East | 500 | Monitor |
| All | 1000 | Laptop |
If no rows meet the selected criteria, FILTER returns an error. In a later step, you can wrap the formula in IFERROR to display a readable message instead.
Exercise
Write a formula that returns columns A through C when the region in F1 matches, treats a blank F1 as “all regions,” and requires sales in column C to be at least the value in F2.
Show answer
=FILTER(A2:C, (F1="")+(B2:B=F1), C2:C>=F2)