Skip to content

Pull the matching rows with FILTER

Formulas that spill8 minPremium

Builds on Fill a range with one formula, and fix #SPILL! and Combine tests with AND, OR and NOT.

Every morning the team lead of a support desk in Austin needs the open tickets out of a log that runs to hundreds of rows. One FILTER formula gives her that list beside the log, and the list changes as tickets close.

How it works

FILTER(array, include, [if_empty]) returns the rows of array whose include value is TRUE. include is a test written over a whole column, such as C2:C20="Open", which gives one TRUE or FALSE for each row, so it covers the same rows as array.

Picture a sieve: every row carries its TRUE or FALSE, and only the TRUE rows fall through, in their original order. The source stays as it is, and the result changes as soon as the data does.

For two tests that must both pass, multiply them: (C2:C20="Open")*(D2:D20="North"). TRUE counts as 1 and FALSE as 0, so the product is 1 only when both are TRUE. Add the tests instead and a row passes when either one is TRUE. When no row passes, FILTER shows #CALC!, unless the third argument gives text to show instead.

Example

A bakery's supply list has the stock of each item in B2:B10 and the level that triggers an order in C2:C10.

=FILTER(A2:A10,B2:B10<C2:C10,"Nothing to order")
Lists the items in A2:A10 whose stock in B2:B10 is below the reorder level on the same row of C2:C10, or Nothing to order when none is.

  1. Step 1: The test B2:B10<C2:C10 asks of every row whether the stock is below its reorder level.
  2. Step 2: Flour, butter, yeast and cocoa are below it, so their rows are TRUE.
  3. Step 3: D2 lists those four items, in the order they come in the list.
The test runs on every row, and only the rows where it's TRUE come through, in the order they appear in the list. In D2, =FILTER(A2:A10,B2:B10<C2:C10,"Nothing to order") returns Flour.

Common mistakes

  • =FILTER(A2:A10,B2:B9<C2:C9) mixes ranges of different heights and shows #VALUE!. Start and end every range on the same rows.
  • AND(C2:C20="Open",D2:D20="North") gives one TRUE or FALSE for both whole ranges, so FILTER shows #VALUE!. Multiply the tests instead, each in brackets.
  • Without the third argument, a test that no row passes shows #CALC!. Give the text to show, such as "None".
  • A test with the value typed in, such as D2:D20="North", has to be edited for the next region. Point it at a cell that holds the region.

In short

  • =FILTER(rows to return, test, text if none) lists the rows where the test is TRUE.
  • Write the test over the whole column, on the same rows as the result.
  • Multiply tests when both must pass and add them when either will do, each in brackets.
  • Give the third argument, or an empty result shows #CALC!.

Practice

Premium

4 exercises: 3 formulas and 1 quiz question.

Practice is part of Premium

Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.