Sub topic 11
Filter with Complex Criteria Using Advanced Filter
AutoFilter handles most everyday filtering. It has limits, though. You cannot combine conditions across columns with OR, you cannot compare against a computed value, and you cannot copy the results to another place on the sheet. Advanced Filter removes these limits. It reads its conditions from a separate block of cells called a criteria range.
This chapter assumes you can select ranges, sort and filter with AutoFilter, and write basic formulas. It also assumes your data has a single header row, no blank rows inside the list, and consistent types in each column.
When to Choose Advanced Filter
Use Advanced Filter when one of these applies:
- You need OR logic across different columns, such as "region is West OR amount is at least 500".
- You need more than two conditions on one column.
- You want the matching rows copied to another location, leaving the source untouched.
- You want a condition based on a formula, such as "amount is above the column average".
- You want a list without duplicate rows in one step.
If the criteria are simple, AutoFilter is faster. If you want results that update automatically, the FILTER function from the next chapter is a better fit. Advanced Filter results do not refresh on their own.
The Three Ranges
Advanced Filter uses up to three ranges.
| Range | Purpose | Notes |
|---|---|---|
| List range | The data to filter, including the header row | Excel often detects it automatically |
| Criteria range | Headers plus condition cells | Must sit outside the list range |
| Copy to | Where results are written | Only used when copying to another location |
Place the criteria range above the data or to the side, with at least one blank row or column between it and the list. Filtering in place hides rows, so a criteria range directly below the data can be hidden or overwritten when the data grows.
Building a Criteria Range
A criteria range has two parts. The top row contains header labels that match the column names in your list exactly. The rows beneath contain the conditions.
Region Amount
West >=500The layout of the conditions controls the logic:
- Conditions on the same row combine with AND.
- Conditions on separate rows combine with OR.
The range above returns rows where Region is West and Amount is at least 500. To get West or any amount of 500 or more, put the conditions on different rows:
Region Amount
West
>=500The criteria range for this version covers three rows: the header and two condition rows.
Operators and Wildcards
Each condition cell can hold a comparison operator followed by a value.
| Entry | Meaning |
|---|---|
| `West` | Text that starts with "West" |
| `=West` | Exactly "West" (see the callout below) |
| `>=500` | Greater than or equal to 500 |
| `<>West` | Not equal to "West" |
| `W*` | Starts with W |
| `*est` | Ends with "est" |
| `=` | Blank cells |
| `<>` | Non-blank cells |
Two Conditions on the Same Column
To apply an AND condition within one column, such as an amount between 500 and 1000, repeat the header:
Amount Amount
>=500 <=1000Both headers must match the list's column name. Excel allows duplicate headers in a criteria range for this purpose.
Running Advanced Filter
- Click any cell inside the data list.
- Open the Data tab and choose Advanced in the Sort & Filter group.
- Choose Filter the list, in place or Copy to another location.
- Confirm the List range, or select it yourself.
- Select the Criteria range, including the header row and every condition row.
- If you chose to copy, click in Copy to and select the top-left cell of the destination. Excel fills the area below and to the right.
- Select Unique records only if you want duplicate rows removed from the result.
- Click OK.
When filtering in place, row numbers turn blue and non-matching rows are hidden. To show everything again, choose Data > Clear in the Sort & Filter group. When copying, the source is not changed, so there is nothing to clear. Delete the copied cells when you no longer need them.
Copying Only Some Columns
When you copy results, Excel normally brings every column. To get a subset, type the headers you want, in the order you want, in the destination row. Then select that header row as the Copy to range. Excel fills only those columns.
Formula-Based Criteria
A criteria cell can contain a formula that returns TRUE or FALSE. This allows conditions that a simple operator cannot express, such as comparing a row to an average.
Two rules apply:
- The header cell above the formula must be blank, or must contain a label that is not one of the list's column names.
- The formula must refer to the first data row of the list using a relative reference, such as D2. Do not use a header cell reference or an absolute reference for the row.
Suppose the data is in A1:D100 with amounts in column D. To keep rows where the amount is above the column average, leave the criteria header blank or give it a label such as "Above average", and enter this formula beneath it:
=D2>AVERAGE($D$2:$D$100)Excel evaluates the formula once for each list row, shifting the relative reference D2 down as it goes. The absolute range inside AVERAGE stays fixed. The criteria cell itself shows TRUE or FALSE, which is normal.
A formula criterion can also combine with other criteria on the same row. A West-region row with an amount above average would hold West under Region and the formula under the label cell, in the same row.
Edge Cases and Common Problems
- Header mismatch. A trailing space or different spelling in a criteria header means that condition matches nothing. Copy the header from the list instead of typing it.
- Blank row in the criteria range. A completely empty row inside the selected criteria range acts as "match everything", so every record passes. Select only the rows that hold conditions.
- Criteria range inside the list's columns. If you put the criteria in rows directly above the list with no gap, Excel can mistake them for part of the data. Leave a blank row.
- Results do not update. Change the data or the criteria, and you must run Advanced Filter again. Use Data > Reapply when filtering in place.
- Copy destination overwrites data. Excel writes over whatever is in the destination area without asking. Choose an empty area.
- Unique records only compares whole rows. Two rows count as duplicates only if every copied column matches. If you copy a subset of columns, the comparison uses only those columns.
- Text and numbers. A criterion of
>=500compares numerically. If the Amount column holds numbers stored as text, nothing matches. Fix the data types first.
Advanced Filter and SUBTOTAL
When you filter in place, hidden rows are excluded from SUBTOTAL results, just as with AutoFilter. The formula =SUBTOTAL(109, D2:D100) therefore totals only the rows that passed your criteria. Keep this formula outside the list range and outside the criteria range so that neither the filter nor the next run can hide it.
Exercise
A list in A1:D100 has the headers Region, Rep, Product, and Amount. You want every row where Region is "West" with Amount of at least 500, plus every row where Region is "East" with Amount under 200. Write the criteria range as text, and state how many rows the range spans.
Show answer
Put the headers in one row and each AND group on its own row, so the two groups combine with OR: Region Amount West >=500 East <200 The range spans three rows: one header row and two condition rows. Region and Amount must match the list headers exactly. To require an exact match instead of "starts with", enter ="=West" and ="=East" in the Region cells.
Exercise
You run Advanced Filter with "Filter the list, in place" and the result contains every row of the list. The criteria range selected was A1:B3, where row 3 is completely empty. What went wrong, and how do you fix it?
Show answer
An empty row inside the criteria range counts as a condition that every record satisfies, so all rows pass. Reselect the criteria range as A1:B2, which holds only the header and the real condition row, then run Advanced Filter again.