keepcalculator

06 Numbers and Powers

Filter with Complex Multiple Criteria? How to Do It

Card No. 06·65930 · Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered
You enter
Finish time, Distance
You get
Average pace, Average speed
Rounding
2 dp

Filtering data with complex multiple criteria means applying several conditions at once to narrow down a dataset—for example, showing only orders over $100 that were placed in the last 30 days and are not from a specific region. You typically do this with spreadsheet functions, database queries, or programming logic, and the exact method depends on the tool you’re using. This article explains the core concepts, common approaches, and pitfalls so you can build the right filter for your data.

Formula

The calculator above computes average pace and speed from a finish time and distance. The formulas are:

  • Pace (min/km) = Finish time (minutes) ÷ Distance (km)
  • Speed (km/h) = Distance (km) ÷ (Finish time (minutes) ÷ 60)

Variables: t = finish time in minutes, d = distance in kilometers. Pace is expressed in minutes per kilometer, and speed in kilometers per hour. This is the standard way runners and cyclists measure performance.

Worked Example

Using the default values: finish time = 50 minutes, distance = 10 km.

  1. Pace = 50 ÷ 10 = 5.00 min/km
  2. Speed = 10 ÷ (50 ÷ 60) = 10 ÷ 0.8333 = 12.00 km/h

The calculator shows 5.00 min/km and 12.00 km/h, matching the formulas.

What Does “Complex Multiple Criteria” Mean?

In data filtering, a single criterion is simple: “Show rows where Region = East.” Multiple criteria combine two or more conditions, often with logical operators like AND, OR, and NOT. For example:

  • AND: Region = East AND Sales > 1000
  • OR: Region = East OR Region = West
  • NOT: NOT (Product = “Widget”)

Complexity arises when you mix these operators, use nested conditions, or apply criteria across different columns. The challenge is getting the logic right—especially the order of operations, which can change the result dramatically.

How Filtering Works in Spreadsheets

Excel and Google Sheets offer several ways to filter with multiple criteria:

  • AutoFilter (the filter icon on the toolbar): lets you choose one condition per column, but you can apply conditions on multiple columns simultaneously. For example, filter Column A to “East” and Column B to “>1000”. This works for simple AND logic across columns.
  • Advanced Filter (Excel only): allows you to write criteria ranges with multiple rows and columns, supporting OR logic and formulas. You set up a separate area with column headers and conditions underneath.
  • FILTER function (Excel 365, Google Sheets): a dynamic array formula that returns all matching rows. For example, =FILTER(A2:C100,(B2:B100="East")*(C2:C100>1000)) uses multiplication as AND and addition as OR.
  • QUERY function (Google Sheets): uses a SQL-like syntax, e.g., =QUERY(A1:C100,"select * where B='East' and C>1000").

Each method has its own syntax and quirks. The FILTER function is popular because it updates automatically when data changes.

Filtering in Databases and Programming

In SQL, you use the WHERE clause with AND, OR, and parentheses to group conditions. For example:

SELECT * FROM orders
WHERE amount > 100
  AND (status = 'shipped' OR status = 'pending')
  AND NOT (region = 'North');

Parentheses are crucial because AND has higher precedence than OR. Without them, the query above would be interpreted differently. In Python (pandas), you can filter a DataFrame with boolean masks:

df[(df['amount'] > 100) & (df['status'].isin(['shipped','pending'])) & (df['region'] != 'North')]

Here, & means AND, | means OR, and ~ means NOT. Always wrap each condition in parentheses.

How to Choose the Right Approach

Your choice depends on the tool, the size of your data, and whether you need a one-off or a reusable filter. Consider:

  • Spreadsheets: Use AutoFilter for quick, manual filtering. Use the FILTER function if you need a dynamic, formula-based result that updates automatically. Use Advanced Filter for complex OR logic across multiple columns.
  • Databases: Use SQL queries. They are efficient on large datasets and can be saved as views.
  • Programming: Use pandas or similar libraries when you need to do further processing after filtering.

Also consider whether you need to filter in place (hiding rows) or produce a new list. AutoFilter hides rows; FILTER creates a new range.

Common Mistakes and Pitfalls

Even experienced users make these errors:

  • Mixing up AND and OR: Using AND when you mean OR (or vice versa) is the most common mistake. For example, “region = East OR region = West” is correct; “region = East AND region = West” returns nothing.
  • Forgetting parentheses: In SQL and programming, not using parentheses can change the logic. Always group conditions explicitly.
  • Using incorrect wildcards: In Excel, the asterisk (*) is a wildcard, but in SQL it’s the percent sign (%). In Google Sheets, you might need to use REGEXMATCH for pattern matching.
  • Case sensitivity: Some tools are case-sensitive (e.g., pandas), while others are not (e.g., Excel AutoFilter). This can lead to missing rows.
  • Blank cells: Filtering on blank cells requires special handling. In Excel, use “Blanks” in AutoFilter; in SQL, use IS NULL.

Always test your filter on a small sample to verify it returns the expected rows.

Frequently Asked Questions

How do I filter with OR logic in Excel?

Use the Advanced Filter with multiple rows in the criteria range. Each row represents an OR condition. For example, to show rows where Region is East OR Sales > 1000, put “Region” and “Sales” in the header row, then under them enter “East” in one row and “>1000” in the next row. The Advanced Filter will match rows that satisfy either condition.

Can I use multiple criteria in Google Sheets FILTER?

Yes. Use the multiplication operator (*) for AND and the addition operator (+) for OR. For example, =FILTER(A:C,(A:A="East")*(C:C>1000)+(B:B="Gold")) returns rows that are either East with sales over 1000, or have a Gold status. Wrap each condition in parentheses and use the correct operator.

What is the difference between AutoFilter and Advanced Filter in Excel?

AutoFilter is quick and easy for simple criteria on one column at a time, but it can’t handle OR logic across columns. Advanced Filter allows you to specify complex criteria in a separate range, including OR conditions, formulas, and computed criteria. It also lets you copy results to another location.

How do I filter with multiple criteria in SQL?

Use the WHERE clause with AND, OR, and NOT operators. Always use parentheses to group conditions. For example: SELECT * FROM table WHERE (col1 = 'A' OR col1 = 'B') AND col2 > 10. Remember that AND is evaluated before OR, so use parentheses to override that order.

Why is my filter not returning the expected results?

Check for common issues: incorrect operator precedence, case sensitivity, extra spaces in data, or using the wrong wildcard. Also verify that your criteria range in Advanced Filter matches the column headers exactly. Test with a small dataset to isolate the problem.

Can I filter based on a formula in Excel?

Yes, in Advanced Filter you can use a formula as a criterion. For example, to filter rows where the value in column A is greater than the average of column A, enter a formula like =A2>AVERAGE(A:A) in the criteria range. The formula should refer to the first data row (e.g., A2) and return TRUE for rows that match.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0 | 100000
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →