The FILTER function allows you to filter a range of data based on criteria you define.
In the following example we used the formula =FILTER(A5:D20,C5:C20=H2,"") to return all records for Apple, as selected in cell H2, and if there are no apples, return an empty string ("").
The FILTER function filters an array based on a Boolean (True/False) array.
=FILTER(array,include,[if_empty])
Argument |
Description |
array Required |
The array, or range to filter |
include Required |
A Boolean array whose height or width is the same as the array |
[if_empty] Optional |
The value to return if all values in the included array are empty (filter returns nothing) |
Notes:
-
An array can be thought of as a row of values, a column of values, or a combination of rows and columns of values. In the example above, the source array for our FILTER formula is range A5:D20.
-
The FILTER function will return an array, which will spill if it's the final result of a formula. This means that Excel will dynamically create the appropriate sized array range when you press ENTER. If your supporting data is in an Excel table, then the array will automatically resize as you add or remove data from your array range if you're using structured references. For more details, see this article on spilled array behavior.
-
If your dataset has the potential of returning an empty value, then use the 3rd argument ([if_empty]). Otherwise, a #CALC! error will result, as Excel does not currently support empty arrays.
-
If any value of the include argument is an error (#N/A, #VALUE, etc.) or cannot be converted to a Boolean, the FILTER function will return an error.
-
Excel has limited support for dynamic arrays between workbooks, and this scenario is only supported when both workbooks are open. If you close the source workbook, any linked dynamic array formulas will return a #REF! error when they are refreshed.
Examples
FILTER used to return multiple criteria
In this case, we're using the multiplication operator (*) to return all values in our array range (A5:D20) that have Apples AND are in the East region: =FILTER(A5:D20,(C5:C20=H1)*(A5:A20=H2),"").
FILTER used to return multiple criteria and sort
In this case, we're using the previous FILTER function with the SORT function to return all values in our array range (A5:D20) that have Apples AND are in the East region, and then sort Units in descending order: =SORT(FILTER(A5:D20,(C5:C20=H1)*(A5:A20=H2),""),4,-1)
In this case, we're using the FILTER function with the addition operator (+) to return all values in our array range (A5:D20) that have Apples OR are in the East region, and then sort Units in descending order: =SORT(FILTER(A5:D20,(C5:C20=H1)+(A5:A20=H2),""),4,-1).
Notice that none of the functions require absolute references, since they only exist in one cell, and spill their results to neighboring cells.
Need more help?
You can always ask an expert in the Excel Tech Community or get support in Communities.