If the data you want to filter requires complex criteria (such as Type = «Produce» OR Salesperson = «Davolio»), you can use the Advanced Filter dialog box.
To open the Advanced Filter dialog box, click Data > Advanced.
Advanced Filter |
Example |
---|---|
Overview of advanced filter criteria |
|
Multiple criteria, one column, any criteria true |
Salesperson = «Davolio» OR Salesperson = «Buchanan» |
Multiple criteria, multiple columns, all criteria true |
Type = «Produce» AND Sales > 1000 |
Multiple criteria, multiple columns, any criteria true |
Type = «Produce» OR Salesperson = «Buchanan» |
Multiple sets of criteria, one column in all sets |
(Sales > 6000 AND Sales < 6500 ) OR (Sales < 500) |
Multiple sets of criteria, multiple columns in each set |
(Salesperson = «Davolio» AND Sales >3000) OR |
Wildcard criteria |
Salesperson = a name with ‘u’ as the second letter |
Overview of advanced filter criteria
The Advanced command works differently from the Filter command in several important ways.
-
It displays the Advanced Filter dialog box instead of the AutoFilter menu.
-
You type the advanced criteria in a separate criteria range on the worksheet and above the range of cells or table that you want to filter. Microsoft Office Excel uses the separate criteria range in the Advanced Filter dialog box as the source for the advanced criteria.
Sample data
The following sample data is used for all procedures in this article.
The data includes four blank rows above the list range that will be used as a criteria range (A1:C4) and a list range (A6:C10). The criteria range has column labels and includes at least one blank row between the criteria values and the list range.
To work with this data, select it in the following table, copy it, and then paste it in cell A1 of a new Excel worksheet.
Type |
Salesperson |
Sales |
Type |
Salesperson |
Sales |
Beverages |
Suyama |
$5122 |
Meat |
Davolio |
$450 |
produce |
Buchanan |
$6328 |
Produce |
Davolio |
$6544 |
Comparison operators
You can compare two values by using the following operators. When two values are compared by using these operators, the result is a logical value—either TRUE or FALSE.
Comparison operator |
Meaning |
Example |
---|---|---|
= (equal sign) |
Equal to |
A1=B1 |
> (greater than sign) |
Greater than |
A1>B1 |
< (less than sign) |
Less than |
A1<B1 |
>= (greater than or equal to sign) |
Greater than or equal to |
A1>=B1 |
<= (less than or equal to sign) |
Less than or equal to |
A1<=B1 |
<> (not equal to sign) |
Not equal to |
A1<>B1 |
Using the equal sign to type text or a value
Because the equal sign (=) is used to indicate a formula when you type text or a value in a cell, Excel evaluates what you type; however, this may cause unexpected filter results. To indicate an equality comparison operator for either text or a value, type the criteria as a string expression in the appropriate cell in the criteria range:
=»=
entry
»
Where entry is the text or value you want to find. For example:
What you type in the cell |
What Excel evaluates and displays |
---|---|
=»=Davolio» |
=Davolio |
=»=3000″ |
=3000 |
Considering case-sensitivity
When filtering text data, Excel doesn’t distinguish between uppercase and lowercase characters. However, you can use a formula to perform a case-sensitive search. For an example, see the section Wildcard criteria.
Using pre-defined names
You can name a range Criteria, and the reference for the range will appear automatically in the Criteria range box. You can also define the name Database for the list range to be filtered and define the name Extract for the area where you want to paste the rows, and these ranges will appear automatically in the List range and Copy to boxes, respectively.
Creating criteria by using a formula
You can use a calculated value that is the result of a formula as your criterion. Remember the following important points:
-
The formula must evaluate to TRUE or FALSE.
-
Because you are using a formula, enter the formula as you normally would, and do not type the expression in the following way:
=»=
entry
» -
Do not use a column label for criteria labels; either keep the criteria labels blank or use a label that is not a column label in the list range (in the examples that follow, Calculated Average and Exact Match).
If you use a column label in the formula instead of a relative cell reference or a range name, Excel displays an error value such as #NAME? or #VALUE! in the cell that contains the criterion. You can ignore this error because it does not affect how the list range is filtered.
-
The formula that you use for criteria must use a relative reference to refer to the corresponding cell in the first row of data.
-
All other references in the formula must be absolute references.
Multiple criteria, one column, any criteria true
Boolean logic: (Salesperson = «Davolio» OR Salesperson = «Buchanan»)
-
Insert at least three blank rows above the list range that can be used as a criteria range. The criteria range must have column labels. Make sure that there is at least one blank row between the criteria values and the list range.
-
To find rows that meet multiple criteria for one column, type the criteria directly below each other in separate rows of the criteria range. Using the example, enter:
Type
Salesperson
Sales
=»=Davolio»
=»=Buchanan»
-
Click a cell in the list range. Using the example, click any cell in the range A6:C10.
-
On the Data tab, in the Sort & Filter group, click Advanced.
-
Do one of the following:
-
To filter the list range by hiding rows that don’t match your criteria, click Filter the list, in-place.
-
To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Tip When you copy filtered rows to another location, you can specify which columns to include in the copy operation. Before filtering, copy the column labels for the columns that you want to the first row of the area where you plan to paste the filtered rows. When you filter, enter a reference to the copied column labels in the Copy to box. The copied rows will then include only the columns for which you copied the labels.
-
-
In the Criteria range box, enter the reference for the criteria range, including the criteria labels. Using the example, enter $A$1:$C$3.
To move the Advanced Filter dialog box out of the way temporarily while you select the criteria range, click Collapse Dialog .
-
Using the example, the filtered result for the list range is:
Type
Salesperson
Sales
Meat
Davolio
$450
produce
Buchanan
$6,328
Produce
Davolio
$6,544
Multiple criteria, multiple columns, all criteria true
Boolean logic: (Type = «Produce» AND Sales > 1000)
-
Insert at least three blank rows above the list range that can be used as a criteria range. The criteria range must have column labels. Make sure that there is at least one blank row between the criteria values and the list range.
-
To find rows that meet multiple criteria in multiple columns, type all the criteria in the same row of the criteria range. Using the example, enter:
Type
Salesperson
Sales
=»=Produce»
>1000
-
Click a cell in the list range. Using the example, click any cell in the range A6:C10.
-
On the Data tab, in the Sort & Filter group, click Advanced.
-
Do one of the following:
-
To filter the list range by hiding rows that don’t match your criteria, click Filter the list, in-place.
-
To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Tip When you copy filtered rows to another location, you can specify which columns to include in the copy operation. Before filtering, copy the column labels for the columns that you want to the first row of the area where you plan to paste the filtered rows. When you filter, enter a reference to the copied column labels in the Copy to box. The copied rows will then include only the columns for which you copied the labels.
-
-
In the Criteria range box, enter the reference for the criteria range, including the criteria labels. Using the example, enter $A$1:$C$2.
To move the Advanced Filter dialog box out of the way temporarily while you select the criteria range, click Collapse Dialog .
-
Using the example, the filtered result for the list range is:
Type
Salesperson
Sales
produce
Buchanan
$6,328
Produce
Davolio
$6,544
Multiple criteria, multiple columns, any criteria true
Boolean logic: (Type = «Produce» OR Salesperson = «Buchanan»)
-
Insert at least three blank rows above the list range that can be used as a criteria range. The criteria range must have column labels. Make sure that there is at least one blank row between the criteria values and the list range.
-
To find rows that meet multiple criteria in multiple columns where any criteria can be true, type the criteria in the different columns and rows of the criteria range. Using the example, enter:
Type
Salesperson
Sales
=»=Produce»
=»=Buchanan»
-
Click a cell in the list range. Using the example, click any cell in the list range A6:C10.
-
On the Data tab, in the Sort & Filter group, click Advanced.
-
Do one of the following:
-
To filter the list range by hiding rows that don’t match your criteria, click Filter the list, in-place.
-
To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Tip: When you copy filtered rows to another location, you can specify which columns to include in the copy operation. Before filtering, copy the column labels for the columns that you want to the first row of the area where you plan to paste the filtered rows. When you filter, enter a reference to the copied column labels in the Copy to box. The copied rows will then include only the columns for which you copied the labels.
-
-
In the Criteria range box, enter the reference for the criteria range, including the criteria labels. Using the example, enter $A$1:$B$3.
To move the Advanced Filter dialog box out of the way temporarily while you select the criteria range, click Collapse Dialog .
-
Using the example, the filtered result for the list range is:
Type
Salesperson
Sales
produce
Buchanan
$6,328
Produce
Davolio
$6,544
Multiple sets of criteria, one column in all sets
Boolean logic: ( (Sales > 6000 AND Sales < 6500 ) OR (Sales < 500) )
-
Insert at least three blank rows above the list range that can be used as a criteria range. The criteria range must have column labels. Make sure that there is at least one blank row between the criteria values and the list range.
-
To find rows that meet multiple sets of criteria where each set includes criteria for one column, include multiple columns with the same column heading. Using the example, enter:
Type
Salesperson
Sales
Sales
>6000
<6500
<500
-
Click a cell in the list range. Using the example, click any cell in the list range A6:C10.
-
On the Data tab, in the Sort & Filter group, click Advanced.
-
Do one of the following:
-
To filter the list range by hiding rows that don’t match your criteria, click Filter the list, in-place.
-
To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Tip: When you copy filtered rows to another location, you can specify which columns to include in the copy operation. Before filtering, copy the column labels for the columns that you want to the first row of the area where you plan to paste the filtered rows. When you filter, enter a reference to the copied column labels in the Copy to box. The copied rows will then include only the columns for which you copied the labels.
-
-
In the Criteria range box, enter the reference for the criteria range, including the criteria labels. Using the example, enter $A$1:$D$3.
To move the Advanced Filter dialog box out of the way temporarily while you select the criteria range, click Collapse Dialog .
-
Using the example, the filtered result for the list range is:
Type
Salesperson
Sales
Meat
Davolio
$450
produce
Buchanan
$6,328
Multiple sets of criteria, multiple columns in each set
Boolean logic: ( (Salesperson = «Davolio» AND Sales >3000) OR (Salesperson = «Buchanan» AND Sales > 1500) )
-
Insert at least three blank rows above the list range that can be used as a criteria range. The criteria range must have column labels. Make sure that there is at least one blank row between the criteria values and the list range.
-
To find rows that meet multiple sets of criteria, where each set includes criteria for multiple columns, type each set of criteria in separate columns and rows. Using the example, enter:
Type
Salesperson
Sales
=»=Davolio»
>3000
=»=Buchanan»
>1500
-
Click a cell in the list range. Using the example, click any cell in the list range A6:C10.
-
On the Data tab, in the Sort & Filter group, click Advanced.
-
Do one of the following:
-
To filter the list range by hiding rows that don’t match your criteria, click Filter the list, in-place.
-
To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Tip When you copy filtered rows to another location, you can specify which columns to include in the copy operation. Before filtering, copy the column labels for the columns that you want to the first row of the area where you plan to paste the filtered rows. When you filter, enter a reference to the copied column labels in the Copy to box. The copied rows will then include only the columns for which you copied the labels.
-
-
In the Criteria range box, enter the reference for the criteria range, including the criteria labels. Using the example, enter $A$1:$C$3.To move the Advanced Filter dialog box out of the way temporarily while you select the criteria range, click Collapse Dialog .
-
Using the example, the filtered result for the list range would be:
Type
Salesperson
Sales
produce
Buchanan
$6,328
Produce
Davolio
$6,544
Wildcard criteria
Boolean logic: Salesperson = a name with ‘u’ as the second letter
-
To find text values that share some characters but not others, do one or more of the following:
-
Type one or more characters without an equal sign (=) to find rows with a text value in a column that begin with those characters. For example, if you type the text Dav as a criterion, Excel finds «Davolio,» «David,» and «Davis.»
-
Use a wildcard character.
Use
To find
? (question mark)
Any single character
For example, sm?th finds «smith» and «smyth»* (asterisk)
Any number of characters
For example, *east finds «Northeast» and «Southeast»~ (tilde) followed by ?, *, or ~
A question mark, asterisk, or tilde
For example, fy91~? finds «fy91?»
-
-
Insert at least three blank rows above the list range that can be used as a criteria range. The criteria range must have column labels. Make sure that there is at least one blank row between the criteria values and the list range.
-
In the rows below the column labels, type the criteria that you want to match. Using the example, enter:
Type
Salesperson
Sales
=»=Me*»
=»=?u*»
-
Click a cell in the list range. Using the example, click any cell in the list range A6:C10.
-
On the Data tab, in the Sort & Filter group, click Advanced.
-
Do one of the following:
-
To filter the list range by hiding rows that don’t match your criteria, click Filter the list, in-place
-
To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Tip: When you copy filtered rows to another location, you can specify which columns to include in the copy operation. Before filtering, copy the column labels for the columns that you want to the first row of the area where you plan to paste the filtered rows. When you filter, enter a reference to the copied column labels in the Copy to box. The copied rows will then include only the columns for which you copied the labels.
-
-
In the Criteria range box, enter the reference for the criteria range, including the criteria labels. Using the example, enter $A$1:$B$3.
To move the Advanced Filter dialog box out of the way temporarily while you select the criteria range, click Collapse Dialog .
-
Using the example, the filtered result for the list range is:
Type
Salesperson
Sales
Beverages
Suyama
$5,122
Meat
Davolio
$450
produce
Buchanan
$6,328
Need more help?
You can always ask an expert in the Excel Tech Community or get support in the Answers community.
Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel for iPad Excel for iPhone Excel for Android tablets Excel for Android phones More…Less
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 the Answers community.
See Also
RANDARRAY function
SEQUENCE function
SORT function
SORTBY function
UNIQUE function
#SPILL! errors in Excel
Dynamic arrays and spilled array behavior
Implicit intersection operator: @
Need more help?
This post will guide you how to extracts matched values using FILTER function in Microsoft Excel 365. And also will introduce that how to use FILTER function with same examples in Excel 365.
Table of Contents
- Excel Filter Function
- Entering FILTER Formula in Excel
- Excel filtering by a single criteria
- Example 1: How to use a number as a filter
- Example 2: How to filter in Excel by a cell value
- Example 3: Using Excel’s text filter
- Example 4: Using NOT EQUAL TO as a FILTER condition in Excel
- Example 5: How to use the date filter in Excel
- Example 6: Filtering by date in Excel
- Example 7: Filtering based on two Conditions
- Example 8: Filtering Based on Two Conditions using OR Logic
- Example 9: Filter Data in Excel from Another Sheet
- Example 10: Providing Maximum Number of Rows of Filtered Data
- Conclusion
- Related Functions
The FILTER function “filters” a set of data according to the conditions specified. The outcome is an array of values that match those in the original range. Simply said, the FILTER function extracts matched records from a collection of data using one or more logical checks. The include argument specifies logical tests, which might encompass a wide variety of formula conditions. For instance, FILTER may match data from a given year or month, data containing specific content, or numbers above a specified threshold.
=FILTER(array,include,[if empty])
Three parameters are required for the FILTER function: array
, include
, and if empty
.
Where:
- Array – This is required argument. The range or array to filter is specified by array.
- Include – This is required argument. Include one or more logical tests in the include These tests should return TRUE or FALSE depending on the array values evaluated.
- If_empty – This is option argument. The last input, if empty, specifies the value to return if FILTER does not discover any matching values. Typically, this is a message along the lines of “No records found,” although other values may also be returned. To show nothing, provide an empty string (“”).
Entering FILTER Formula in Excel
FILTER provides dynamic results. When the values in the source data change or the size of the source data array changes, the FILTER results are updated automatically. The results of FILTER will “leak” into numerous cells on the worksheet.
To filter data in Excel using the FILTER function, follow these steps:
Step1: To begin your filter formula, enter =FILTER(
.
Step2: Enter the address for the range of cells containing the data you want to filter, for example, A2:C10.
Step3: Type a comma, followed by the filter's condition
, such as B2:B20>3
(To specify a condition, type the address of the “criteria column,” such as C1:C, followed by an operator symbol such as greater than (>), and finally the criterion, such as the number 3.
Step4: Complete the parenthesis with a closing parenthesis and then hit enter on the keyboard. Your full formula will appear as follows: =FILTER(A2:C10, B2:B20>3)
I’ll begin with the fundamentals of utilizing the FILTER function, and then demonstrate some more advanced uses of the FILTER function. This article discusses the FILTER function as a formula entered into spreadsheet cells, not the filter command accessible from the toolbar and pop-up menus.
While using the FILTER function in Excel is almost identical to using it in Google Sheets, there are some subtle variations.
Excel filtering by a single criteria
To begin, let’s review how to use Excel’s FILTER function in its simplest version, with a single condition/criteria.
I’ll demonstrate how to filter data using a number, a cell value, a text string, or a date… and I’ll also demonstrate how to utilize a variety of “operators
” in the filter condition (Less than, Equal to, etc…).
Example 1: How to use a number as a filter
In this first demonstration of how to use the filter tool in Excel, we have a list of students and their grades and wish to create a filtered list of only students with flawless grades.
The assignment: Display a list of students and their grades, but only those who have earned an A.
The reasoning: Filter the range A2:B10 for values larger than 0.7 in the column B2:B10 (70 percent ). Then you can use the following FILTER formula,type:
=FILTER(A2:B10, B2:B10 >0.7)
Example 2: How to filter in Excel by a cell value
In this excel filter function example, we want to do the same thing as stated before, but rather than inputting the condition straight into the formula, we’re going to use a cell reference.
When you filter in Excel by a cell value, your sheet is configured in such a way that you may alter the value in the cell at any moment, which updates the value to which the filter criterion is tied.
In this example, rather than explicitly entering the value “0.8” into the formula, the filter criterion is set to cell G1, which contains the “0.8
” value.
The assignment: Display a list of students and their grades, but only those with a score of less than 80%
.
The reasoning: Filter the range A2:B10 to the extent that B2:B10 is smaller than the value supplied in column G1 (0.8).
You can use the following FILTER formula, type:
=FILTER(A2:B10, B2:B10 <G1)
Example 3: Using Excel’s text filter
In this example, we’ll utilize a text string as the filter formula’s criterion. This is fairly similar to using a number, except that the text to filter must be enclosed in quote marks.
We are filtering a list of customers and their payment status in this instance, and we want to present just customers with a payment status of “Payed
“.
The objective is to provide a list of clients that have paid on their payments.
The reasoning: Filter the range A2:B6 by substituting the string “ Payed
” for B2:B6.
The following formula: In this example, the formula below is typed in the cell (E1).
=FILTER(A3:B12, B2:B6=" Payed ")
Example 4: Using NOT EQUAL TO as a FILTER condition in Excel
Now that you have a working knowledge of how to use the filter function in Excel, here is another example of filtering by a string of text, but this time we will use the “not equal” operator (<>) to demonstrate how to filter a range and return data that is NOT equal to the criteria you set.
Additionally, we will utilize a bigger data set in this example to show a more comprehensive usage of the FILTER function in the real world.
You may be surprised at how often a circumstance arises in which you need to filter data that is “not equal to
” a certain number or piece of text.
In this example, we’ll use a report/spreadsheet to display data from sales calls that occur at your organization, and we’ll filter the data to exclude a certain sales person (Scott) from the result.
The assignment: Display sales call statistics for all sales representatives except ” Scott “.
The reasoning: Filter the range A2:C10
for values A2:A10
that DO NOT match the string “Scott “.
The following formula: In this example, the formula below is typed in the cell (E1).
=FILTER(A2:C10, A2:A10 <>"Scott")
Take note that the filtered data on the right side of the figure above does not include any of Scott
‘s rows/calls.
Example 5: How to use the date filter in Excel
Filtering in Excel by a date may be accomplished in a few different methods, which I will demonstrate below. If you attempt to put a date into the FILTER function in the same way that you would typically type into a cell, the formula will fail to operate properly.
Therefore, you may either enter the date you want to filter into a cell and then reference that cell in your formula… Alternatively, you may use the DATE function.
When filtering by date, the same operators (>, =, etc…) are available as they are in other FILTER function applications. Each individual day/date in Excel is merely a number that has been formatted differently. In Excel, for example, the date “01/30/2022
” is just the serial number “44591
” formatted as a date. Each time you add a day to the calendar, this number increases by one… For example, “44591” “44592” “44593”
Thus, if one date is farther in the future, it might be regarded “greater than
” another. In contrast, if one date is farther in the past, it might be considered to be “less than
” another.
In this example, we’ll use a cell reference to filter on a date. This is identical to the example discussed in Example 2, except that we are dealing with dates instead of percentages.
Consider the following scenario: we want to filter a list of students, their exam results, and the dates on which the tests were administered… and we wish to display only tests conducted before to June (05/01/2022).
=FILTER(A2:C10, C2:C10 <G1)
Example 6: Filtering by date in Excel
In this example of date filtering in Excel, we’ll use the same data as in the previous one and attempt to obtain the same results… however, instead of referencing a cell, we’ll utilize the DATE function, which allows you to put the date straight into the FILTER function.
When using the DATE function to provide a date, you must first input the year, followed by the month and finally the day… each denoted with a comma (shown below).
The assignment: Display only exams given before to May
The reasoning: Filter the range A2:C10
so that C2:C10
is less than or equal to the date (05/01/2022).
The following formula: In this example, the formula below is typed in the cell (D3).
=FILTER(A2:C10,C2:C10<DATE(2022,5,1))
Example 7: Filtering based on two Conditions
When utilizing the Excel FILTER function, you may want to produce data that fits many criteria. I’ll demonstrate two methods for filtering by several criteria in Excel, depending on the scenario and the desired behavior of the calculation.
The conventional method of adding another condition to your filter function (as shown by the Excel formula syntax) allows you to provide a second condition, where both the first AND second conditions must be fulfilled in order for the filter output to be returned.
However, I will demonstrate how to make a little tweak to the function so that you may choose to return/display in the filter function’s output/destination a second condition where EITHER condition might be satisfied. (To utilize AND logic, separate the conditions with an asterisk, or use a plus symbol to separate the criteria.)
In this example, we’re going to filter a collection of data and show those rows that satisfy BOTH the first and second conditions.
To utilize a second condition in this manner (using AND logic), just insert it after the first condition in the formula, separated by an asterisk (*)
. Each condition must be included in a separate pair of parentheses.
When a filter formula is used with several conditions, the columns referenced in each condition must be distinct.
In this case, we’d want to filter a list of clients based on their payment status and region… and to display those customers who are both current members AND paid on their payment status.
The objective is to provide a list of customers who are paid on payments, but only those who are in East region.
The reasoning: Filter the range A2:C6 such that B2:B6 equals the text “Paid
,” AND C2:C6 equals the text “East
“.
The following formula: In this example, the formula below is typed in the blue cell (E1).
=FILTER(A2:C6,( B2:B6="Paid")*( C2:C6 ="East"))
Example 8: Filtering Based on Two Conditions using OR Logic
In this example, we’re going to filter a collection of data and show those rows that satisfy either the first OR the second criterion.
To utilize a second condition in this manner (using OR logic), just insert it after the first condition in the formula, separated by a plus sign
. Each condition must be included in a separate pair of parentheses (shown below).
When used in this manner, the FILTER formula allows you to choose criteria from the same or separate columns.
In this case, we’re filtering the same customer data as in the previous example, but this time we’re displaying a list of customers who either are in East
region OR have paid on a payment. This will generate a list of clients to whom a payment notification have paid… whether they are current members or east region who have paid on their last payment.
The objective is to provide a list of customers who are in East
region, as well as customers who have paid on payments regardless of whether they are in East region.
The following formula: In this example, the formula below is typed in the cell (E1).
=FILTER(A2:C6, (B2:B6="Paid ")+(C2:C6=" East ")
Example 9: Filter Data in Excel from Another Sheet
You may often encounter instances in Excel when you need to filter data from another sheet, where your raw unfiltered data is on one tab and your filter formula is on another sheet.
This may be accomplished by simply referring to a certain sheet’s name when providing the filter’s ranges. Thus, while you would typically give a range such as “A1:B4,” when referring another sheet when filtering, you indicate the sheet name by preceding the range with the sheet name and an exclamation mark, as in “SheetName!A1:B4
“.
However, if the sheet name contains a space, an apostrophe must be used before and after the sheet name, as in "Sheet Name!" A1:B4
.
The following is an example of how to filter data in Excel from a separate sheet, where the filter formula is located on a different sheet than the source range.
Consider the following scenario: On one sheet, you have a list of customers and their payment status, and you wish to present a filtered list of paid customer on another sheet.
The job is to filter the list of customers on the Sheet3 and to display a separate list of customer names with a pay status on another worksheet.
The reasoning: Filter the range using the Sheet3
‘ command! A2:C6, where ‘ Sheet3′ is the range! B2:B6 corresponds to the phrase “Paid“.
The following formula: In this example, the formula below is typed in the cell (A3).
=FILTER(Sheet3! A2:C6, Sheet3!B2:B6="Paid")
Example 10: Providing Maximum Number of Rows of Filtered Data
If your FILTER formula provides a large number of rows but your worksheet is restricted in space and you are unable to erase the data below, you may limit the amount of rows returned by the FILTER function.
Let us demonstrate how it works using a simple formula that filter data that grade is less than 0.7 from filter value in Cell F1:
=FILTER(A2:C10, B2:B10<F1)
The preceding formula produces all records that it discovers, in this instance five rows. However, imagine you only have room for two. To output just the first two rows discovered, follow these steps:
Step1: Incorporate the FILTER formula into the INDEX function’s array parameter
Step2: Use a vertical array constant such as 1;2 as the row num input to INDEX. It specifies the number of rows to return (2 in our case).
Step3: Use a horizontal array constant such as 1,2 for the column num parameter. It defines the columns that should be returned (the first 2 columns in this example).
Step4: To account for any mistakes caused by the absence of data meeting your criteria, you may wrap your calculation in the IFERROR function.
The entire excel filter formula is as follows:
=IFERROR(INDEX(FILTER(A2:C10, B2:B10<F1), {1;2},{1,2}), "No Found")
Conclusion
This section discusses the FILTER function and its many uses. In general, when it comes to time management, we need this feature for a variety of reasons. I demonstrated various techniques with accompanying examples, however there might be countless further iterations based on a variety of circumstances. If you know of another way to use this function, please share it with us.
- Excel IFERROR function
The Excel IFERROR function returns an alternate value you specify if a formula results in an error, or returns the result of the formula.The syntax of the IFERROR function is as below:= IFERROR (value, value_if_error)…. - Excel INDEX function
The Excel INDEX function returns a value from a table based on the index (row number and column number)The INDEX function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the INDEX function is as below:= INDEX (array, row_num,[column_num])…
The FILTER function «filters» a range of data based on supplied criteria. The result is an array of matching values from the original range. In plain language, the FILTER function will extract matching records from a set of data by applying one or more logical tests. Logical tests are supplied as the include argument and can include many kinds of formula criteria. For example, FILTER can match data in a certain year or month, data that contains specific text, or values greater than a certain threshold.
The FILTER function takes three arguments: array, include, and if_empty. Array is the range or array to filter. The include argument should consist of one or more logical tests. These tests should return TRUE or FALSE based on the evaluation of values from array. The last argument, if_empty, is the result to return when FILTER finds no matching values. Typically this is a message like «No records found», but other values can be returned as well. Supply an empty string («») to display nothing.
The results from FILTER are dynamic. When values in the source data change, or the source data array is resized, the results from FILTER will update automatically. Results from FILTER will «spill» onto the worksheet into multiple cells.
Basic example
To extract values in A1:A10 that are greater than 100:
=FILTER(A1:A10,A1:A10>100)
To extract rows in A1:C5 where the value in A1:A5 is greater than 100:
=FILTER(A1:C5,A1:A5>100)
Notice the only difference in the above formulas is that the second formula provides a multi-column range for array. The logical test used for the include argument is the same.
Note: FILTER will return a #CALC! error if no matching data is found
Filter for Red group
In the example shown above, the formula in F5 is:
=FILTER(B5:D14,D5:D14=H2,"No results")
Since the value in H2 is «red», the FILTER function extracts data from array where the Group column contains «red». All matching records are returned to the worksheet starting from cell F5, where the formula exists.
Values can be hardcoded as well. The formula below has the same result as above with «red» hardcoded into the criteria:
=FILTER(B5:D14,D5:D14="red","No results")
No matching data
The value for is_empty is returned when FILTER does not find matching results. If a value for if_empty is not provided, FILTER will return a #CALC! error if no matching data is found:
=FILTER(range,logic) // #CALC! error
Often, is_empty is configured to provide a text message to the user:
=FILTER(range,logic,"No results") // display message
To display nothing when no matching data is found, supply an empty string («») for if_empty:
=FILTER(range,logic,"") // display nothing
Values that contain text
To extract data based on a logical test for values that contain specific text, you can use a formula like this:
=FILTER(rng1,ISNUMBER(SEARCH("txt",rng2)))
In this formula, the SEARCH function is used to look for «txt» in rng2, which would typically be a column in rng1. The ISNUMBER function is used to convert the result from SEARCH into TRUE or FALSE. Read a full explanation here.
Filter by date
FILTER can be used with dates by constructing logical tests appropriate for Excel dates. For example, to extract records from rng1 where the date in rng2 is in July you can use a generic formula like this:
=FILTER(rng1,MONTH(rng2)=7,"No data")
This formula relies on the MONTH function to compare the month of dates in rng2 to 7. See full explanation here.
Multiple criteria
At first glance, it’s not obvious how to apply multiple criteria with the FILTER function. Unlike older functions like COUNTIFS and SUMIFS, which provide multiple arguments for entering multiple conditions, the FILTER function only provides a single argument, include, to target data. The trick is to create logical expressions that use Boolean algebra to target the data of interest and supply these expressions as the include argument. For example, to extract only data where one value is «A» and another is greater than 80, you can use a formula like this:
=FILTER(range,(range="A")*(range>80),"No data")
The math operation of addition (*) joins the two conditions with AND logic: both conditions must be TRUE in order for FILTER to retrieve the data. See a detailed explanation here.
Complex criteria
To filter and extract data based on multiple complex criteria, you can use the FILTER function with a chain of expressions that use boolean logic. For example, the generic formula below filters based on three separate conditions: account begins with «x» AND region is «east», and month is NOT April.
=FILTER(data,(LEFT(account)="x")*(region="east")*NOT(MONTH(date)=4))
See this page for a full explanation. Building criteria with logical expressions is an elegant and flexible approach that can be extended to handle many complex scenarios. See below for more examples.
Notes
- FILTER can work with both vertical and horizontal arrays.
- The include argument must have dimensions compatible with the array argument, otherwise FILTER will return #VALUE!
- If the include array includes any errors, FILTER will return an error.
Watch Video – Excel Advanced Filter
Excel Advanced Filter is one of the most underrated and under-utilized features that I have come across.
If you work with Excel, I am sure you have used (or at least heard about the regular excel filter). It quickly filters a data set based on selection, specified text, number or other such criteria.
In this guide, I will show you some cool stuff you can do using the Excel advanced filter.
But First… What is Excel Advanced Filter?
Excel Advanced Filter – as the name suggests – is the advanced version of the regular filter. You can use this when you need to use more complex criteria to filter your data set.
Here are some differences between the regular filter and Advanced filter:
- While the regular data filter will filter the existing dataset, you can use Excel advanced filter to extract the data set to some other location as well.
- Excel Advanced Filter allows you to use complex criteria. For example, if you have sales data, you can filter data on a criterion where the sales rep is Bob and the region is either North or South (we will see how to do this in examples). Office support has some good explanation on this.
- You can use the Excel Advanced Filter to extract unique records from your data (more on this in a second).
EXCEL ADVANCED FILTER (Examples)
Now let’s have a look at some example on using the Advanced Filter in Excel.
Example 1 – Extracting a Unique list
You can use Excel Advanced Filter to quickly extract unique records from a data set (or in other words remove duplicates).
In Excel 2007 and later versions, there is an option to remove duplicates from a dataset. But that alters your existing data set. To keep the original data intact, you need to create a copy of the data and then use the Remove Duplicates option. Excel Advanced filter would allow you to select a location to get a unique list.
Let’s see how to use an advanced filters to get a unique list.
Suppose you have a dataset as shown below:
As you can see, there are duplicate records in this data set (highlighted in orange). These could be due to an error in data entry or result of data compilation.
In such a case, you can use Excel Advanced Filter tool to quickly get a list of all the unique records in a different location (so that your original data remains intact).
Here are the steps to get all the unique records:
This will instantly give you a list of all the unique records.
Caution: When you are using Advanced Filter to get the unique list, make sure you have also selected the header. If you don’t, it would consider the first cell as the header.
Example 2 – Using Criteria in Excel Advanced Filter
Getting unique records is one of the many things you can do with Excel advanced filter.
Its primary utility lies in its ability to allow using complex criteria for filtering data.
Here is what I mean by complex criteria. Suppose you have a dataset as shown below and you want to quickly get all the records where the sales are greater than 5000 and the region is the US.
Here is how you can use Excel Advanced Filter to filter the records based on the specified criteria:
This would instantly give you all the records where the region is the US and the sales are more than 5000.
The above example is a case where the filtering is done based on two criteria (US and sales greater than 5000).
Excel Advanced filter allows you to create many different combinations of criteria.
Here are some examples of how you can construct these filters.
Using the AND Criteria
When you want to use AND criteria, you need to specify it below the header.
For example:
Using the OR Criteria
When you want to use OR criteria, you need to specify the criteria in the same column.
For example:
By now, you must have realized that when we have the criteria in the same row, it is an AND criteria, and when we have it in different rows, it is an OR criteria.
Example 3 – Using WILDCARD Characters in Advanced Filter in Excel
Excel Advanced Filter also allows the usage of wildcard characters while constructing the criteria.
There are three wildcard characters in Excel:
- * (asterisk) – It represents any number of characters. For example, ex* could mean excel, excels, example, expert, etc.
- ? (question mark) – It represents one single character. For example, Tr?mp could mean Trump or Tramp.
- ~ (tilde) – It is used to identify a wildcard character (~, *, ?) in the text.
Now let’s see how we can use these wildcard characters to do some advanced filtering in Excel.
- To filter records where the sales rep name starts from J.
Note that * represent any number of characters. So any rep with the name starting with J would be filtered with these criteria.
Similarly, you can use the other two wildcard characters as well.
Note: In case you’re using Office 365, you should check out the FILTER function. It can do a lot of things that advanced filter can do with a simple formula.
NOTE:
- Remember, the headers in the criteria should be exactly the same as that in the data set.
- Advanced filtering cannot be undone when copied to other locations.
You May Also Like the Following Excel Tutorials:
- Dynamic Excel Filter – Extract Data as you Type.
- Filtering Cells with Bold Font Formatting.
- How to Filter Cells that have Duplicate Text Strings (Words) in it.
- How to Filter Data in a Pivot Table in Excel
- MS Guide for Advanced Filter in Excel.
- How to Compare Two Columns in Excel.
- Excel VBA Autofilter
- 20 Advanced Excel Functions and Formulas (for Excel Pros)