The FILTER function
FILTER pulls out the rows that pass a test and spills them below the formula. Unlike the Filter button, it's a formula: change the data or the condition and the results update.
For more than one condition, put each test in brackets and multiply them (…)*(…) for AND, or add them (…)+(…) for OR.
=FILTER(array, include, [if_empty])
Arguments
- array
- The range to return rows from.
- include
- A test for each row, such as
B2:B8="North". It must be the same height asarray. Multiply tests for AND, add them for OR. - if_emptyoptional
- What to show when no rows match, such as
"None". Without it you get #CALC!.
Try it
=FILTER(A2:C8,B2:B8="North") in E2. The three North orders (1041, 1043 and 1045) spill into E2:G4 with all three columns.
E2
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Order | Region | Amount | Order | Region | Amount | ||
| 2 | 1041 | North | £120 | 1041 | North | £120 | ||
| 3 | 1042 | South | £45 | 1043 | North | £85 | ||
| 4 | 1043 | North | £85 | 1045 | North | £240 | ||
| 5 | 1044 | Midlands | £310 | |||||
| 6 | 1045 | North | £240 | |||||
| 7 | 1046 | South | £150 | |||||
| 8 | 1047 | Midlands | £60 | |||||
| 9 | ||||||||
| 10 |
Edit the formula in E2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =TEXTJOIN(", ",TRUE,FILTER(A2:A8,(B2:B8="North")*(C2:C8>100))) | 1041, 1045 | Multiplying the tests means both must be true: North and over £100. |
| =ROWS(FILTER(A2:A8,(B2:B8="South")+(C2:C8>300))) | 3 | Adding the tests means either can be true: the two South orders plus the £310 one. |
| =FILTER(A2:A8,B2:B8="Wales","No orders") | No orders | No row matches, so the if_empty text is shown. |
| =FILTER(A2:A8,B2:B8="Wales") | #CALC! | Without if_empty, an empty result is a #CALC! error. |
Tips
- Put the condition in a cell, e.g.
=FILTER(A2:C8,B2:B8=J1), so anyone can change the report. - Wrap FILTER in SORT to order the results:
=SORT(FILTER(A2:C8,B2:B8="North"),3,-1). - Return only some columns by giving a narrower array, such as A2:A8 for just the order numbers.
Common mistakes
- FILTER returns #VALUE!.The include test must be the same height as the array. B2:B8 with A2:C8 works; B2:B9 doesn't.
- You used AND(B2:B8="North",C2:C8>100) and got nothing useful.AND collapses everything into a single TRUE or FALSE. Multiply the tests instead:
(B2:B8="North")*(C2:C8>100). - You get #SPILL!.Clear the cells below and to the right of the formula so the results have room.
In Google Sheets
In Google Sheets, list extra conditions as further arguments instead of multiplying them: =FILTER(A2:C8, B2:B8="North", C2:C8>100). All of them must be true. Sheets' FILTER has no if_empty argument, so wrap it in IFERROR to show a message when nothing matches.
Practise FILTER with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.