{ }Dynamic arrays11 min read ·

How to Use the FILTER Function in Excel

Learn the Excel FILTER function with real examples. Multiple criteria with AND and OR, cells that contain text, if_empty, SORT, UNIQUE and fixing #SPILL!

Quick answer

=FILTER(array, include, [if_empty])

FILTER returns every row that meets a condition and spills the results into the cells below, like =FILTER(B2:B9, C2:C9="Lighting"). For several conditions, multiply the tests for AND and add them for OR.

Arguments in [brackets] are optional.

On this page ⌄
  1. The FILTER syntax
  2. A basic FILTER example
  3. When nothing matches: if_empty and #CALC!
  4. FILTER with multiple criteria (AND)
  5. FILTER with OR conditions
  6. Filter rows that contain text
  7. Return only some columns
  8. FILTER with SORT and UNIQUE
  9. How to fix the #SPILL! error
  10. Common FILTER mistakes
  11. Frequently asked questions about FILTER
  12. Which versions of Excel have FILTER?
  13. Key takeaways

FILTER returns every row of a table that meets a condition. You tell it what to return and which rows to keep, and the matching rows spill into the cells below the formula. When the data changes, the list updates by itself:

=FILTER(array, include, [if_empty])

It works like the Filter button on the Data tab, except the original table stays as it is, and the result is a live list you can sort, count or use in other formulas. FILTER is available in Microsoft 365, Excel 2021 and later, and Excel for the web.

The examples use this inventory in A1:E9:

A: SKUB: ProductC: CategoryD: PriceE: Stock
2P-01Desk lampLighting$39120
3P-02Office chairFurniture$18914
4P-03Standing deskFurniture$4490
5P-04Monitor armAccessories$7956
6P-05Floor lampLighting$890
7P-06BookshelfFurniture$12931
8P-07Cable trayAccessories$25210
9P-08Desk matAccessories$190

Each formula below goes in H2, with the cells under and beside it empty, so the results have room to spill.

The FILTER syntax

ArgumentWhat it meansExample
arrayThe cells to return: one column, several columns or the whole tableB2:B9
includeA test that gives TRUE or FALSE for each row. FILTER keeps the TRUE rowsC2:C9="Lighting"
if_emptyOptional. What to return when no row passes the test"No matches"

The include test must cover the same rows as array. If array is B2:B9, the test must check rows 2 to 9 too. It doesn't have to test a column you're returning, so you can return names while testing prices.

A basic FILTER example

Which products are in the Lighting category?

=FILTER(B2:B9, C2:C9="Lighting")→ Desk lamp, Floor lamp

You type the formula once, in H2, and press Enter. FILTER checks C2:C9 row by row, keeps the two rows that say Lighting, and spills their names into H2 and H3. Click H3 and the formula bar shows the formula grayed out, because it lives in H2.

The test can be any comparison. Which products have more than 50 in stock?

=FILTER(B2:B9, E2:E9>50)→ Desk lamp, Monitor arm, Cable tray

To return whole rows, make array the whole table:

=FILTER(A2:E9, C2:C9="Lighting")
HIJKL
2P-01Desk lampLighting39120
3P-05Floor lampLighting890

FILTER returns values, not formatting, so the prices show as plain numbers until you format column K as currency. Dates come back as numbers too, so format them as dates.

Your turn. The sheet below is live and uses the same inventory. This time the exercise asks for a different category: change what you compare column C with, then press Enter and watch the list spill.

Try it yourself

A live spreadsheet. Type a formula and press Enter to check it.

Exercise 1 of 11FILTER

List every product in the Furniture category.

Write your formula in the green cell, H2.

inventory.xlsx
fx
1SKUProductCategoryPriceStock
2P-01Desk lampLighting$39.00120Furniture
3P-02Office chairFurniture$189.0014
4P-03Standing deskFurniture$449.000
5P-04Monitor armAccessories$79.0056
6P-05Floor lampLighting$89.000
7P-06BookshelfFurniture$129.0031
8P-07Cable trayAccessories$25.00210
9P-08Desk matAccessories$19.000
10
11

Click a cell to add it to your formula, drag to select a range, or click a column letter for the whole column.

When nothing matches: if_empty and #CALC!

If no row passes the test, FILTER has nothing to return, so it shows #CALC!. There's no Outdoor category, and nothing costs more than $500:

=FILTER(B2:B9, C2:C9="Outdoor")→ #CALC!
=FILTER(B2:B9, D2:D9>500)→ #CALC!

The third argument, if_empty, is what FILTER shows instead:

=FILTER(B2:B9, C2:C9="Outdoor", "No matches")→ No matches

Use "" as if_empty to leave the cell looking blank. When at least one row matches, if_empty is ignored, so it's safe to add to any FILTER whose test could come up empty, such as one driven by a drop-down.

It's also safer than wrapping FILTER in IFERROR, because IFERROR hides real mistakes too. Here the test is one row short, C2:C8 instead of C2:C9:

=FILTER(B2:B9, C2:C8="Lighting", "No matches")→ #VALUE!
=IFERROR(FILTER(B2:B9, C2:C8="Lighting"), "No matches")→ No matches

The first formula tells you something is wrong. The second claims there are no Lighting products, when there are two.

FILTER with multiple criteria (AND)

To keep only the rows that pass two tests, put each test in brackets and multiply them. Which products cost under $100 and are in stock?

=FILTER(B2:B9, (D2:D9<100)*(E2:E9>0))→ Desk lamp, Monitor arm, Cable tray

Each test gives a TRUE or FALSE for every row. When you multiply them, Excel treats TRUE as 1 and FALSE as 0, so a row only scores 1 when both tests are TRUE:

RowProductD2:D9<100E2:E9>0Multiplied
2Desk lampTRUETRUE1
3Office chairFALSETRUE0
4Standing deskFALSEFALSE0
5Monitor armTRUETRUE1
6Floor lampTRUEFALSE0
7BookshelfFALSETRUE0
8Cable trayTRUETRUE1
9Desk matTRUEFALSE0

FILTER keeps every row that isn't 0. You can multiply as many tests as you need. A price between $50 and $150 is two tests on the same column:

=FILTER(B2:B9, (D2:D9>=50)*(D2:D9<=150))→ Monitor arm, Floor lamp, Bookshelf

FILTER with OR conditions

To keep rows that pass either test, add the tests instead. Which products are Lighting or Accessories?

=FILTER(B2:B9, (C2:C9="Lighting")+(C2:C9="Accessories"))→ Desk lamp, Monitor arm, Floor lamp, Cable tray, Desk mat

The results stay in the same order as the table. Adding gives 0 when neither test is TRUE, and 1 or more when at least one is. A row that passes both tests scores 2, but FILTER still lists it once. Here are the Accessories, plus anything with more than 100 in stock:

=FILTER(B2:B9, (C2:C9="Accessories")+(E2:E9>100))→ Desk lamp, Monitor arm, Cable tray, Desk mat

Cable tray is an accessory with 210 in stock, so it passes both tests, but it appears only once.

You can mix OR and AND, as long as you add brackets around the OR part. This lists Lighting or Furniture products, but only the ones in stock:

=FILTER(B2:B9, ((C2:C9="Lighting")+(C2:C9="Furniture"))*(E2:E9>0))→ Desk lamp, Office chair, Bookshelf

Excel multiplies before it adds, so without the extra brackets the stock test only applies to Furniture, and the out-of-stock Floor lamp slips in:

=FILTER(B2:B9, (C2:C9="Lighting")+(C2:C9="Furniture")*(E2:E9>0))→ Desk lamp, Office chair, Floor lamp, Bookshelf

Filter rows that contain text

FILTER's test is a plain comparison, so wildcards don't work in it. B2:B9="*desk*" looks for a product literally named *desk*, finds none and returns #CALC!.

To match part of a cell, use SEARCH. It returns the position of the text, or a #VALUE! error if the text isn't there, and ISNUMBER turns that into TRUE or FALSE:

=FILTER(B2:B9, ISNUMBER(SEARCH("desk", B2:B9)))→ Desk lamp, Standing desk, Desk mat

SEARCH ignores upper and lower case, so "desk" finds Desk lamp as well as Standing desk. For a case-sensitive match, use FIND instead:

=FILTER(B2:B9, ISNUMBER(FIND("desk", B2:B9)))→ Standing desk

Don't leave out ISNUMBER. SEARCH gives an error for every row that doesn't match, and FILTER passes that error on instead of skipping the row.

Return only some columns

The array argument decides which columns come back. For columns that sit next to each other, narrow the range. Here are the product, category and price of everything with more than 100 in stock:

=FILTER(B2:D9, E2:E9>100)
HIJ
2Desk lampLighting39
3Cable trayAccessories25

For columns that aren't next to each other, wrap FILTER in CHOOSECOLS and list the columns you want, counted from the left of array. Here are the name and stock of each accessory:

=CHOOSECOLS(FILTER(A2:E9, C2:C9="Accessories"), 2, 5)
HI
2Monitor arm56
3Cable tray210
4Desk mat0

CHOOSECOLS needs Microsoft 365, Excel 2024 or Excel for the web. In Excel 2021, use a second FILTER on the columns. Give it a row of 1s and 0s, one for each column, where 1 means keep:

=FILTER(FILTER(A2:E9, C2:C9="Accessories"), {0,1,0,0,1})

This returns the same two columns.

FILTER with SORT and UNIQUE

FILTER keeps the order of the table. Wrap it in SORT to put the results in order. These are the products in stock, A to Z:

=SORT(FILTER(B2:B9, E2:E9>0))→ Bookshelf, Cable tray, Desk lamp, Monitor arm, Office chair

To sort a result with several columns, give SORT the column to sort by and -1 for largest first. This lists the products in stock, by price from highest to lowest:

=SORT(FILTER(B2:D9, E2:E9>0), 3, -1)
HIJ
2Office chairFurniture189
3BookshelfFurniture129
4Monitor armAccessories79
5Desk lampLighting39
6Cable trayAccessories25

The 3 means the third column of the filtered result, Price, not column C of the sheet.

UNIQUE removes repeats. Which categories have a product with more than 50 in stock?

=FILTER(C2:C9, E2:E9>50)→ Lighting, Accessories, Accessories
=UNIQUE(FILTER(C2:C9, E2:E9>50))→ Lighting, Accessories
=SORT(UNIQUE(FILTER(C2:C9, E2:E9>50)))→ Accessories, Lighting

For a single number instead of a list, wrap FILTER in SUM, AVERAGE or COUNTA. This adds up the stock of every accessory:

=SUM(FILTER(E2:E9, C2:C9="Accessories"))→ 266

With one condition, =SUMIFS(E2:E9, C2:C9, "Accessories") gives the same 266 and works in every version of Excel. See the SUMIF and SUMIFS guide. FILTER earns its place when the condition is something SUMIFS can't do, like an OR across two columns.

How to fix the #SPILL! error

FILTER needs an empty cell for every result. If anything is in the way, even a space or a formula that returns "", you get #SPILL! instead of the list. The three accessories need H2:H4, so with something typed in H3:

=FILTER(B2:B9, C2:C9="Accessories")→ #SPILL!

Click the formula cell and Excel draws a dashed border around the cells it wants to use. Clear H3 and the list appears. To check how many rows a FILTER needs, COUNTIF counts the matches: =COUNTIF(C2:C9, "Accessories") returns 3.

The other common causes:

  • The formula is inside an Excel table. Spilled formulas don't work in tables. Move the formula outside the table.
  • Merged cells are in the way. Unmerge them, or move the formula.

Common FILTER mistakes

ProblemWhat's going onFix
#CALC!No row passed the testAdd if_empty, such as "No matches"
#VALUE!array and include cover different rows, like B2:B9 and C2:C8Make both ranges the same height
#SPILL!The cells the list needs aren't empty, or the formula is in a tableClear the cells, or move the formula
#NAME?Excel 2019 or older, or a typo in FILTERUse Microsoft 365 or Excel 2021 or later
#REF!The data is in another workbook that's closedOpen both workbooks
AND or OR in the test doesn't workThey return one answer for the whole range, not one per rowMultiply tests for AND, add them for OR
"*desk*" finds nothingWildcards aren't supported in the testUse ISNUMBER(SEARCH("desk", B2:B9))
0 where the source cell is blankFILTER returns empty cells as 0For text columns, add &"" to array, as in B2:B9&""

Frequently asked questions about FILTER

Is FILTER case-sensitive?

No. C2:C9="lighting" matches Lighting. For an exact-case match, test with EXACT:

=FILTER(B2:B9, EXACT(C2:C9, "Lighting"))→ Desk lamp, Floor lamp

What's the difference between FILTER and XLOOKUP?

XLOOKUP returns the first match only. FILTER returns every match:

=XLOOKUP("Lighting", C2:C9, B2:B9)→ Desk lamp
=FILTER(B2:B9, C2:C9="Lighting")→ Desk lamp, Floor lamp

Use XLOOKUP when each value appears once, such as an ID, and FILTER when you want them all. The XLOOKUP guide covers lookups in detail.

Does FILTER pick up new rows?

Only if its ranges cover them. If you add a product in row 10, B2:B9 misses it. Format the data as an Excel table with Ctrl+T, and use the table's column names so the ranges grow with it. If the table is named Inventory:

=FILTER(Inventory[Product], Inventory[Category]="Lighting")

Put the formula outside the table, because spilled formulas can't go inside one.

How do I filter by a drop-down?

Point the test at the cell instead of typing the value. With a drop-down of categories in G1, made with Data Validation:

=FILTER(B2:B9, C2:C9=G1, "No matches")

Pick a different category and the list changes.

Which versions of Excel have FILTER?

FILTER works in Microsoft 365, Excel 2021, Excel 2024 and Excel for the web, on Windows and Mac. It isn't in Excel 2019 or older, where it returns #NAME?. If a file has to work in those versions, use the Filter button on the Data tab, or INDEX and MATCH when you only need the first match.

Google Sheets has FILTER too, but extra conditions go in as separate arguments, as in =FILTER(B2:B9, D2:D9<100, E2:E9>0), and there's no if_empty argument. For Microsoft's own examples, see the FILTER function page.

For more practice, the dynamic arrays topic has Premium exercises on FILTER with AND, FILTER with OR and adding up a filtered list.

Key takeaways

  • =FILTER(array, include, [if_empty]) returns every row where include is TRUE, and the results spill into the cells below.
  • Multiply tests for AND, add them for OR, and give each test its own brackets.
  • Add if_empty so an empty result shows a message instead of #CALC!, and clear the cells in the way when you see #SPILL!.
  • FILTER needs Microsoft 365, Excel 2021 or later, or Excel for the web.

Practice

Keep going with FILTER exercises

Reading gets you started. Solving a few of these is what makes it stick.

  1. 1Filter a listFreeList every product in the Furniture category.→
  2. 2Out of stock PremiumList the products that are out of stock (Stock is 0).→
  3. 3FILTER with AND PremiumList the Accessories that are in stock (Stock more than 0).→
  4. 4FILTER with OR PremiumList every product that is in Lighting or is out of stock.→
  5. 5Stock value with FILTER PremiumWhat's the total stock value (Price × Stock) of Accessories? Use FILTER.→
All dynamic arrays exercises →
Brian Millot

About the author

Brian Millot

Brian Millot is an indie hacker based in France who builds small, focused web products. He built and runs Excel Formula Practice, from the in-browser spreadsheet that checks your formulas to the exercise library, and he writes the formula guides.

Related guides

Practice makes formulas

Stop reading. Start typing formulas.

Every exercise is a real spreadsheet with instant feedback. The first two in every topic are free, no sign-up needed.