How to Filter Data Based on a List in Another Tab in Google Sheets

You can filter data based on a list in another tab in Google Sheets using the FILTER function combined with the XMATCH function. This approach allows you to dynamically extract data that matches a predefined list of criteria from another sheet.

Generic Formula:

=FILTER(range, XMATCH(criteria_range, list))  

For example, the following formula filters the range A2:B in Sheet1 based on a list of items in A2:A5 in Sheet2:

=FILTER(Sheet1!A2:B, XMATCH(Sheet1!A2:A, Sheet2!A2:A5))  

This formula matches the items in A2:A of Sheet1 with the list in A2:A5 of Sheet2.

Example: Filter Data Based on a List in Another Tab

The sample data includes the date, fruit names, and quantity in the range A1:C of Sheet1, with headers in row 1. The filter range is A2:C, and the criteria range is the list in A2:A5 of Sheet2.

Sample data in one tab and a criteria list in another tab in Google Sheets

To filter this range based on a list of fruit names in A2:A5 from Sheet2, use this formula:

=FILTER(Sheet1!A2:C, XMATCH(Sheet1!B2:B, Sheet2!A2:A5))

This formula works seamlessly to filter data based on a list in another tab. You can insert it in either Sheet1 or Sheet2.

Example of filtering data based on a list in another tab in Google Sheets

Common Errors to Watch Out For:

  • #N/A:
    • This error occurs if the list is empty or the values in the list do not match the column being filtered (e.g., B2:B in Sheet1).
    • Double-check that you’re referencing the correct columns and that the list in Sheet2 contains relevant values.
  • #REF!:
    • This error means the formula cannot expand because of pre-existing values in the output cells.
    • Ensure there is enough empty space to display the filtered results.

The combination of FILTER and XMATCH is the easiest way to filter data based on a list in another tab. If you need case-sensitive filtering, you can replace the XMATCH function with REGEXMATCH, as described below.

Formula Explanation

FILTER Function Syntax:

FILTER(range, condition1, [condition2, …]) 
  • range: The data to filter (Sheet1!A2:C in this case).
  • condition1: The filter condition (XMATCH(Sheet1!B2:B, Sheet2!A2:A5)).

XMATCH Function:

The XMATCH function checks whether each value in Sheet1!B2:B exists in the list Sheet2!A2:A5. It returns the position of the match or an #N/A error if no match is found.

The FILTER function then includes rows where XMATCH returns a position (i.e., a number). This allows you to dynamically filter data based on a list in another tab.

Case-Sensitive Filtering

By default, XMATCH is case-insensitive. For example, it treats “APPLE,” “apple,” and “Apple” as identical.

To filter data based on a list in another tab with case sensitivity, replace the XMATCH condition with a REGEXMATCH condition:

REGEXMATCH(Sheet1!B2:B, "^" & TEXTJOIN("$|^", TRUE, Sheet2!A2:A5) & "$")

Updated formula:

=FILTER(Sheet1!A2:C, REGEXMATCH(Sheet1!B2:B, "^" & TEXTJOIN("$|^", TRUE, Sheet2!A2:A5) & "$"))

How REGEXMATCH Works

  • Pattern: The TEXTJOIN function creates a regex pattern like this: ^Peaches$|^Oranges$|^Watermelons$|^Mangoes$
  • Breakdown:
    • ^: Ensures the match starts at the beginning of the string.
    • $: Ensures the match ends at the end of the string.
    • |: Acts as an OR operator between the words.
    • Matches exact strings like “Peaches,” “Oranges,” “Watermelons,” or “Mangoes.”

This pattern ensures that only exact matches are included when you filter data based on a list in another tab.

If you omit the ^ and $ symbols, the formula will allow partial matches, which may not be desirable in some cases.

Wrap-Up

We’ve explored two methods to filter data based on a list in another tab:

  1. Case-Insensitive Filtering: Using the XMATCH function for simplicity.
  2. Case-Sensitive Filtering: Using the REGEXMATCH function for precision.

Both approaches are highly effective, but XMATCH is easier to use if case sensitivity is not required.

You can also apply these formulas to filter data based on a list in the same tab by adjusting the list reference accordingly.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Extract Numbers from Text in Excel with Regex

You can use the REGEXEXTRACT or REGEXREPLACE functions to easily extract numbers from text...

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

How to Use OFFSET and XMATCH Functions Together in Excel

We often use the OFFSET and XMATCH functions together to match a value in...

How to Calculate Maximum Drawdown in Excel and Google Sheets

You can use the following dynamic array formula to calculate maximum drawdown (MDD) in...

More like this

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

Running Count with Structured References in Google Sheets

Running a count with structured references is achievable in Google Sheets tables using the...

Running Total with Structured Table References in Google Sheets

You can use two types of formulas to create a running total with structured...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.