Excel Advanced Filter
Excel Advanced Filter
Books and Articles Addins: Excel PowerPoint Tutorials: Excel VBA Tips Charts
Miscellanea Custom Consulting
Home > Publications & Training > Business Data Management > Excel Advanced Filter
The primary version of Excel for this document is Excel 2010 but the techniques should work with older Search
versions of Excel (Excel 2007 and Excel 2003) with some changes to the terminology (e.g., an Excel 2010
Table is an Excel 2003 List).
Filter and sort are complementary but otherwise totally different capabilities. A filter uses a consumer defined criteria to show a
subset of the original data. An example might be to show all customers whose orders remain unshipped. On the other hand, to
sort data means to keep the entire original data set intact but to organize it in a way convenient to the consumer. An example of
sort might be to organize the data so that the customer names are in alphabetic order or so that the orders are shown in
descending sequence based on the ordered quantity.
For those who are unfamiliar with AutoFilter (or would like a refresher), search Bing (or Google) or visit
http://office.microsoft.com/en‐us/excel‐help/filter‐data‐in‐a‐range‐or‐table‐HP010073941.aspx
The layout of this document is as follows: 1) Introduction to the data set used in the examples, 2) Introduction to the Advanced
Filter dialog box, 3) Filter using column headers, 4) Filter using Excel formulas, 5) Extract unique data, 6) Work with dynamic
source data, and 7) Create a filter in a different worksheet or workbook.
The table provides information about the status of each item in each order placed by customers. When a customer places an
order, it is given a unique Order ID. Each product is uniquely identified by Product. If an order includes multiple products, there
is one row in the table for each combination of Product & Order ID. For each order‐product combination, the table tracks the
order date (Order Date), the product ship date (Shipped Date), which will be empty if the product is not yet shipped, the
customer name (Customer), the quantity ordered (Quantity), and the unit price (Unit Price).
Figure 1
We will explore a range of management questions that we can answer with Advanced Filter in support of business operations.
Advanced Filter
Advanced Filter provides many features for data‐based filtering that are not available in AutoFilter. Because Advanced Filter
works with the data and not the formatting, the color‐related capabilities of Autofilter are outside the scope of an advanced
filter. At the same time, Advanced Filter delivers to the Excel consumer a very powerful filter and extract tool. For those who
have used SQL (or have heard of SQL but have been uncertain about learning it), Advanced Filter represents an easy and Excel‐
friendly way to tap into some of the power of SQL.
To access the Advanced Filter dialog box (Figure 2) select any cell in the source range and click the Data tab | Sort & Filter group
| Advanced button. This dialog box is deceptively simple given that it actually packs a lot of capability.
Figure 2
Use the choices under Action to either “Filter the list, in‐place” (very much like what AutoFilter does) or to extract a Copy to
another location of the selected data. I find the latter (i.e., copy to another location) to be the more useful feature since it leaves
the original data untouched and all the rows remain visible. It also makes it possible to simultaneously view the results of
different queries and to save the results of different queries for future review.
The List range field specifies the Excel range containing the source data. In our example it is Sheet1!A1:G60.
The Criteria range is optional. This might seem strange since shouldn’t a criteria be required to filter data? But, it turns out that
leaving this out can be a powerful mechanism. Also, when specified, and unlike AutoFilter, the criteria are entered in a
worksheet range. This, particularly when combined with copying the result to another location, allows one to “save” both the
criteria and the corresponding result for future review. It also allows one to ask extremely sophisticated questions, since the
content of the criteria range can be any Excel formula.
When the selected action is Copy to another location, the Copy to field allows one to specify where Excel should save the results.
Use this field to specify which columns to include in the output.
Finally, the Unique records only checkbox indicates that the result should have no duplicate results, where duplicates are defined
as having the same value in every output column.
This requires specifying a single value for the Product column as shown in Figure 3. The dialog box also shows that the result will
be copied to the range starting with J8.
Figure 3
The result, shown in Figure 4, lists all the product orders that relate to NT Dried Plums.
Figure 4
Figure 6
In this case, the conditions are Product=”NT Dried Plums” and Quantity > 30 and Quantity <=30. Remember that ANDed
conditions have to be on the same row and there are two conditions that involve Quantity! Luckily, Advanced Filter allows
columns to be duplicated as in Figure 7.
Figure 7
The last few examples have shown how to specify various elements of the Advanced Filter dialog box. Subsequent examples will
focus on the conditions in the cells and may skip showing the contents of the Advanced Filter dialog box.
Figure 9
Figure 10
Example 6: Combine AND and OR
List the Product, Order ID, and Quantity for all orders for quantities greater than 10 and for either Dried Plums or Dried Pears.
Remember that AND conditions go in a single row and OR conditions go in separate rows. In this case, Excel will evaluate each
row independentaly and then check the OR part. So, the correct way to write the logical requirement is (Quantity > 10 and
Product=”NT Dried Plums”) or (Quantity > 10 and Product=”NT Dried Pears”) as in Figure 11
Figure 11
Figure 13
Figure 15
Figure 16
Figure 17
Example 13: Working with dates III – Empty dates
List all products that remain unshipped. Ensure that the output is verifiable.
An unshipped product will have an empty Shipped Date. Adapt the earlier suggestion for finding an exact match (Example 11)
except this time specify nothing in the search expression as in Figure 18. Also, to ensure a verifiable output, include the Shipped
Date column. Obviously, it should contain only empty cells.
Figure 18
Figure 19
Figure 21
Example 16: Use a formula to combine multiple conditions
List all product orders that remain unshipped or were shipped more than 7 days after the order was placed.
This essentially is Example 14 combined with Example 15. The formula is shown in Figure 22.
Figure 22
This is similar to the previous example except that it involves an ‘and’ condition as well as a specific date in the formula (rather
than comparing two dates that are already in the table). The formula and the associated result are in Figure 23. As should be
expected the result should match Example 14 with the exception of the last 2 orders (order 79 and order 80), which were placed
on June 30, 2012, i.e., 6 days before July 6, 2012.
Figure 23
Example 18: A calculated field as a condition – II
List all product orders that generated revenues in excess of 2,000.
This requires calculating the revenue from the existing columns. The revenue is the quantity (column F) multiplied by the unit
price (column G), which makes the problem similar to Example 15 (which required calculating the difference between two
columns). The criteria and the result are in Figure 24.
Figure 24
Example 20: Compare the row ‘value’ relative to the overall data set
List all product orders where the quantity ordered is more than 50% greater than the average quantity.
In this example, the comparison will be between each row of data and a statistical measure applied to the entire data set. What
is required is to test whether the quantity is more than 1.5 * average quantity ordered per product. This translates to the
formula and result in Figure 26.
Figure 26
Advanced Filter criteria must be a regular formula and not an array formula
Array formulas, for those who know about them, represent a powerful computation capability within Excel. Unfortunately, the
Advanced Filter criteria range cannot contain such a formula. If it does, Excel will return no results. Consequently, it becomes
necessary to find a workaround, when possible, to the use of an array formula in a filter criteria formula.
Example 21: Advanced Filter criteria with a workaround to an array formula
List all product orders where the revenue is more than 50% greater than the average revenue.
This looks very much like Example 20 but it requires the use of a calculated field. The most obvious way might be the formula =
(F2*G2)>1.5*AVERAGE($F$2:$F$60*$G$2:$G$60). This will yield a #VALUE! error since it must be entered as an array formula.
After than is done, and Advanced Filter is given this criteria range, the result will be no rows in the output.
An alternative formulation for this array formula is the non‐array formula =
(F2*G2)>1.5*SUMPRODUCT($F$2:$F$60*$G$2:$G$60)/COUNT($G$2:$G$60). With this criteria Excel returns the correct result
for Advanced Filter as in Figure 27.
Figure 27
Obviously, not every array formula has an equivalent non‐array formula and in those cases Advanced Filter will not provide the
desired functionality.
Figure 29
Example 24: Unique records that meet a condition
List all customers affected by unshipped orders placed earlier than 7 days prior to July 6, 2012.
This is similar to Example 17 except that the result should be a unique list of affected customers as in Figure 30.
Figure 30
Figure 31
Figure 32
Working with the source list in another workbook is similar. Start with the destination worksheet in the destination workbook.
The rest of the mechanics of creating the criteria formula and the references in the dialog box are the same. Obviously, the
references are longer because, now, they also have to include the workbook name as in Figure 34.
Figure 34
One final note on working with another workbook: Even when copying the data to another location, the source workbook must
be open for Advanced Filter to work.
Summary
This document provides what is hopefully a comprehensive review of the Advanced Filter capability in Excel 2010 and Excel
2007.
Excel 2010, Excel 2007, data analysis, advanced filter; advance filtering; custom filter; filter advanced; advanced filter
criteria; remove advanced filter; advanced data filter; advanced sort & filter;
Comments
Optional If you will take a moment to provide your comments, it will help improve the site both for you, and for other visitors.
Monitor page
for changes
enter email
OK
it's private
by ChangeDetection
Copyright © 2000‐2009 Tushar Mehta.
Send comments and suggestions about the web site to web‐underscore‐contact@tushar‐hyphen‐mehta‐dot‐cee‐oh‐em
Last edited December 27, 2012