This post may contain affiliate links. Please read my disclosure for more info.
Advertisement:

FILTER function in Excel

FILTER Function Thumb

FILTER Function

Filtering is a common, everyday action for most Excel users.  Whether using AutoFilter or a Table, it is a convenient way to view a subset of data quickly.  Until 24 September 2018 there was no way to achieve this with formulas.  On that day, Microsoft announced some new functions which make use of the new calculation engine.  One of those new functions is FILTER, which returns all the cells from a range which meet specific criteria.

At the time of writing, Microsoft has only made this new functionality available to Office 365 subscribers on the Insider channel.  The updates will be rolled out to all Office 365 subscribers at a future point, but first Microsoft need to assess the impact the changes to the calculation engine will have.  The new dynamic array functions and features are not available in Excel 2019 or previous versions, so it is definitely worth getting an Office 365 subscription, otherwise, you will be waiting until Excel 2022, and that’s just too long to wait!

Before we look at the arguments required for the FILTER function, let’s look at a basic example to appreciate what it does.

FILTER - Basic Example

Here the FILTER function is returning all the values in Cells B3-B10 where the number of characters is greater than 15.  Not a scenario many of us will need, but it does show the power of the new FILTER function.

 

Arguments of the FILTER function

FILTER has three arguments:

=FILTER(array, include, [if_empty])
  • array: The range of cells, or array of values to filter.
  • include: An array of TRUE/FALSE results, where the TRUE values will be retained in the filter.
  • [if_empty]: The value to display if no rows are returned.

 

Examples of using the FILTER function

The following examples illustrate how to use the FILTER function.

 

Example 1 – FILTER returns an array of rows and columns

In this example, Cell F3 contains a single formula, but this single formula returns an array of values into the neighboring rows and columns.

FILTER - Example 1

The formula in Cell G3 is:

=FILTER(B3:D10,C3:C10>100)

Advertisement:

This single formula is returning 2 rows and 3 columns of data where the values in C3-C10 are greater 100.

 

Example 2 – #CALC error caused by the FILTER function

The screenshot below displays what happens when the result of the FILTER function has zero results.

FILTER - Example 2a

The formula in Cell F3 is:

=FILTER(B3:D10,C3:C10>200)

As there are no rows meeting the criteria (Invoice Value greater than 200), the FILTER cannot return a value, so the #CALC error is displayed.

Thankfully, Microsoft has given us the if_empty argument, which displays a default message if there are no rows returned.

FILTER - Example 2b

The formula in Cell F3 is:

=FILTER(B3:D10,C3:C10>200,"No Results")

In the screenshot above, “No Results” displays instead of the #CALC error.

If we wanted to display a result in each column, we could include a constant within the if_empty argument.  The following would display n/a in the Invoice Value and Days Due columns.

=FILTER(B3:D10,C3:C10>200,{"No Results","n/a","n/a"})

 

Example 3 – FILTER expands automatically when linked to a Table

This example shows how the FILTER function responds when linked to an Excel Table.

FILTER - Example 3a

This FILTER function is using a Table called tblInvoices as its source.  New records added to the Table which meet the criteria are automatically added to the spill range of the function.  Amazing stuff!


Advertisement:

 

Example 4 – Using FILTER with multiple criteria.

Example 4 shows how to apply FILTER with multiple criteria.

FILTER Example 4

The formula in Cell F3 is:

=FILTER(B3:D10,(C3:C10>50)*(D3:D10>15))

For anybody who has used the SUMPRODUCT function before, this method of applying multiple conditions will be familiar.  Multiplication creates AND conditions (i.e., all the criteria in each row must be TRUE).  The example above shows where the Invoice Value is greater than 50 and the Days Due is greater than 15.

Addition creates OR conditions (i.e., any value in the row can be TRUE).

FILTER Example 4a

The formula in Cell G3 is:

=FILTER(B3:D10,(C3:C10>50)+(D3:D10>15))

The example above shows where the Invoice Value is greater than 50 or the Days Due is greater than 15.

 

Example 5 – Using FILTER for dependent dynamic drop-down lists

Drop-down lists are a data validation technique.  Dependent drop-down lists change depending on the result of another cell.  For example, if the first drop-down list displays country names, the second drop-down list should display only cities which exist in that country.  There are currently only very tedious methods to achieve this effect, but the new FILTER makes this super easy.

FILTER - Example 5

The formula in Cell H3 is:

=UNIQUE(B3:B10)

The UNIQUE function creates a unique list to populate the drop-down in Cell F4.

The formula in Cell I3 is:

=FILTER(C3:C10,B3:B10=F4)

Advertisement:

Depending on the value in Cell F4, the values returned by the FILTER function change.  The second drop-down in Cell F6 changes dynamically based on the value in Cell F4.

 

Example 6 – Using FILTER with other functions

In this final example, FILTER is nested inside the SORT function.

FILTER - Example 6

The formula in Cell F3 is:

=SORT(FILTER(B3:D10,D3:D10<=30))

First, the FILTER function returns the cells based on the Days Due being less than or equal to 30.  The SORT function then puts the Customers into ascending alphabetical order.

 

Want to learn more?

There is a lot to learn about dynamic arrays and the new array functions.  Check out my other posts here to learn more:

  • Introduction to dynamic arrays – learn how the excel calculation engine has changed.
  • UNIQUE – to list the unique values in a range
  • SORT – to sort the values in a range
  • SORTBY – to sort values based on the order of other values
  • FILTER – to return only the values which meet specific criteria
  • SEQUENCE – to return a sequence of numbers
  • RANDARRAY – to return an array of random numbers

Also, here are some other resources you might find useful:

Leave a Reply

Your email address will not be published. Required fields are marked *