Advanced Filtering in Excel

Advanced Filtering in Excel

By Bob Umlas, Excel MVP

In this blog I’ll continue the discussion from my last blog on basic filtering. This one is on advanced filtering.

Let’s continue with the same worksheet used from the last blog:

You can use advanced filtering for any of the features you use basic filtering. The advanced feature enables you to do things that can’t be done with basic filtering. For example, how would you filter this data for items in which the Sales times the Units is over 30,000,000? You can’t, unless you add another column containing this calculation and then filter on that new column. But as you’ll see, you don’t need to do that with the advanced filter. Let’s take a look at what the advanced filter looks like.

It’s on the Data tab:

When you select this, you see a dialog box which you fill in:

If the active cell is inside a range of data, then the first field is pre-filled with the address of the contiguous range of cells. You can change this to be any range, but you usually leave it as is. The worksheet I used for this blog has data in A1:F59. The next, and perhaps most important part of the advanced filter, is the Criteria range. This is a range of cells containing at least 2 rows and at least 1 column. Usually, the top row is one of the column header cells, like Product, or Region in the above illustration. For example:

Cell H5 contains the column header from cell F1, “Region”. The criteria range in the dialog was created by clicking in the field, and then dragging across the 2 cells in column H. (“Filtering” is the name of the sheet tab, and preceded the address if you drag across the cells). You could have simply typed H5:H6 in the Criteria Range box.

But what does this mean? The top row identifies the column, and the 2nd row identifies what to filter this column by. You would definitely not use the advanced filter for this simple filter; I’m just demonstrating how this works. The result, when clicking OK is as expected, rows containing only North Region:

Let’s examine a more involved filter.

This time, the criteria range is 3 rows, not 2. This is how you indicate an or condition. The region is North or West. The result:

When there’s more than 1 column, it becomes an and condition:

This means you want to see all rows which have a Region of North and a Salesperson of Davolio:

You’re not limited to 2 columns. This filter adds 3 fields together:

That means that the Region must be North and the Salesperson must be Davolio and the Product must be Produce. You would enter this information manually before using the Advanced Filter.

The above yields this:

You can also have more than 2 rows and more than one column! This filter will show those rows where the Salesperson is Davolio and the Product is Produce, or the Region is South and the Product is Meat:

Let’s get back to the filter which can show those rows where sales times units is over 30 million. There’s no column you can use, so you resort to what’s called a “computed criteria”. It’s ok to have some kind of labeling in the top row of this column (or it may be left blank) – just don’t use a label that matches something in the headers being filtered, or this will not work as it is intended.

It might look like this:

The top row is clearly blank (H2), so this is a computed criteria. But what’s that “TRUE” in H3? As in all computed criteria, it’s a formula which specifies the criteria, and refers to the first data row (row 2 in this example) as an example to apply to every row. Cell H3 contains the formula =C2*D2>30000000:

It’s the test we want to apply to every row: Sales times Units (columns C and D) must be more than 30,000,000. Here’s the result:

(It’s accurate. I tested it!)

You can combine computed criteria with non-computed criteria as well! In this example, using just B for the salesperson will treat it as a wild card, indicating any Salesperson beginning with B:

Cell H3 contains the formula =YEAR(B2)=2017. This criteria is getting all rows in which the year is 2017 (even though the dates contain month and year), and the Region is North and the Salesperson begins with B:

If I wanted to see some field which is exactly equal to just B, and not just beginning with B, you have to use a very non-intuitive formula: =”=B”.
If you want something to be not equal to something, you could use this as the criteria:

You may also have noticed the choice in the filter dialog to Copy to another location.

This advanced criteria will copy all records in which the region contains an s (all except North) to cell I1 as the starting cell:

Notice that the “North” records are filtered out (See column N).

Here’s a trick that not many people know about. If you have cells already filled in with the data headers you want, as in J1:K1 below, you can limit or reorder the extract columns. This is easier shown than explained. Suppose you have your worksheet set up like this:

Note the computed criteria of C2<3000, meaning the filter will be for Sales under 3000:

The “trick” part is that the copy to location is J1:L1, and those cells already contain information. See what happens:

Only those columns which were referenced are extracted from the source data!

What if I wanted to copy to a different sheet, like Sheet3, below?

This gives an error message:

Hmmm. What if we start from that sheet?

Notice I’m starting the advanced filter from a totally empty sheet! I can fill in the fields:

(The criteria range is pointing to Region of North or West):

These records were “pulled” from the Filtering sheet. Cool! And if the empty sheet had Units in A1 and Product in B1:

That extract which points to these cells:

gives:

Okay, nearing the end. What is Unique records only?

Using this advanced filter:

(Notice the list range was changed to be column F only), and cell H5 is empty. When I click OK:

I have a list of unique items from the Region field.

Happy Advanced filtering!

If you are interested in bringing Excel MVP Bob Umlas into your company (either virtually or traditionally) to do Excel consulting and/or training work, contact roxi.nevin@iil.com.


About the Author
Bob Umlas has been using Excel since its inception in 1986. He has had more than 300 articles published on subjects ranging from beginner to advanced, VBA, tips, shortcuts, and general techniques using virtually all aspects of Excel. He is the longest running Microsoft Excel MVP in the world (25 years). He has been the technical editor of (about 20) of Bill Jelen’s (MrExcel) Excel books. Bob speaks at Excel conferences around the world on his favorite topic, Tips & Tricks, which wows even the experts. He is the author of 3 Excel books and is the current leader of NYC’s Excel Special Interest Group (which meets on the 2nd Tuesday of each month).

Books:
This isn’t Excel, it’s Magic!
Excel Outside the Box
More Excel Outside the Box