HomeGoogle DocsSpreadsheetGoogle Sheets Pivot Table Filter Multiple Values (Custom Formula)

Google Sheets Pivot Table Filter Multiple Values (Custom Formula)

Google Sheets Pivot Tables don’t let you specify multiple values in the built-in Text contains or Text does not contain filters. The workaround is to use a custom formula with REGEXMATCH, allowing you to include or exclude multiple text values in a single condition.

This tutorial shows you exactly how to do that.

Formula Cheat Sheet

DescriptionFormula
Multiple Conditions – Text Doesn’t Contain (Case Sensitive)=REGEXMATCH(Attempt,"2nd|3rd")=FALSE
Multiple Conditions – Text Doesn’t Contain (Case Insensitive)=REGEXMATCH(Attempt,"(?i)2nd|3rd")=FALSE
Multiple Conditions – Exact Match (Case Sensitive)=REGEXMATCH(Attempt,"^2nd$|^3rd$")=FALSE
Multiple Conditions – Exact Match (Case Insensitive)=REGEXMATCH(Attempt,"(?i)^2nd$|^3rd$")=FALSE

Replace FALSE with TRUE to use Text contains instead of Text doesn’t contain.

Note: Enclose column names containing spaces in single quotes. For example, use 'Item No' instead of Item No.

Sample Data and Pivot Table

Suppose you have the following sample data in the range B2:D10.

ParticipantsAttemptScore
alphaalpha 1st attempt10
charliecharlie 1st attempt20
charliecharlie 2nd attempt10
alphaalpha 2nd attempt20
betabeta 1st attempt20
charliecharlie 3rd attempt20
deltadelta 1st attempt10
deltadelta 2nd attempt60

Create a Pivot Table from the above data.

  1. Select the data.
  2. Click Insert > Pivot table.
  3. In the Pivot table editor, add Participants under Rows and Score under Values.

You will get a Pivot Table like the one below.

Sample data and Google Sheets Pivot Table before applying a custom filter

Now suppose you want to exclude rows where the Attempt field contains “2nd” or “3rd”. Notice that Attempt isn’t used in the Pivot Table itself.

The built-in Text does not contain filter only accepts a single value. For example, you can exclude 2nd or 3rd, but not both at the same time.

To filter multiple values, use a custom formula instead.

Multiple Values in Text Does Not Contain

To exclude rows containing 2nd or 3rd, use one of the following formulas in the Custom formula is field.

Case-sensitive

=REGEXMATCH(Attempt,"2nd|3rd")=FALSE

Case-insensitive

=REGEXMATCH(Attempt,"(?i)2nd|3rd")=FALSE

To exclude more values, simply separate them with the pipe (|) operator.

2nd|3rd|4th|5th

The pipe symbol (|) acts as the OR operator in regular expressions. The above pattern matches 2nd, 3rd, 4th, or 5th.

How to Add the Custom Formula

  1. Click Add next to Filters in the Pivot table editor.
  2. Select the field to filter (Attempt in this example).
  3. Choose Filter by condition > Custom formula is.
  4. Paste one of the formulas above.
Applying a REGEXMATCH custom formula to filter multiple values in a Google Sheets Pivot Table

Using REGEXMATCH in a Pivot Table vs. a Worksheet

The formula used in the Pivot Table filter is slightly different from the one you would use in a worksheet.

For example, if you test the formula in a worksheet, you’ll need to use a range reference instead of the field name.

=ARRAYFORMULA(REGEXMATCH(C3:C10,"2nd|3rd"))
ARRAYFORMULA and REGEXMATCH example showing which rows match the values "2nd" or "3rd"

Keep these differences in mind:

  • When using the formula in a worksheet, use the cell range (for example, C3:C10) instead of the field name.
  • Since the reference is an array, wrap the formula with ARRAYFORMULA.
  • Inside the Pivot Table editor, neither of these is required. You can simply use the field name (Attempt).

REGEXMATCH returns TRUE when the text matches the specified pattern.

Since we want Text does not contain, we append =FALSE so matching rows are excluded.

Multiple Values in Text Contains

If you want to include only rows containing specific values, replace =FALSE with =TRUE.

=REGEXMATCH(Attempt,"2nd|3rd")=TRUE

Google Sheets Pivot Table Filter Multiple Values Using Exact Match

The previous formulas perform partial matching (similar to Text contains and Text does not contain).

If you want to match only the exact text, use start (^) and end ($) anchors in the regular expression.

Partial match

2nd|3rd
(?i)2nd|3rd

Exact match

^2nd$|^3rd$
(?i)^2nd$|^3rd$

Replace 2nd and 3rd with the exact text values you want to match.

FAQ

Can I use multiple conditions in the built-in Text contains or Text doesn’t contain filter in a Google Sheets Pivot Table?

No. The built-in filter only supports a single condition. To filter by multiple values, use a REGEXMATCH formula in the Custom formula is field.

Can I use MATCH or XMATCH instead of REGEXMATCH?

Not for this use case. Both MATCH and XMATCH support the * and ? wildcards (XMATCH requires match_mode set to 2). However, the wildcard matching applies only to the search key, not the lookup values. Since we need to match the field value against multiple criteria, REGEXMATCH is the better choice.

Does the custom formula automatically include new rows added to the source data?

Yes. As long as the Pivot Table’s source range includes empty rows below the existing data before you apply the custom formula, newly added rows will be included automatically when the Pivot Table refreshes.

Conclusion

Although Google Sheets Pivot Tables don’t support filtering by multiple values using the built-in Text contains and Text does not contain conditions, you can achieve the same result with REGEXMATCH in a custom formula. By combining multiple values with the pipe (|) operator, you can easily include or exclude several text values in a single Pivot Table filter.

Prashanth K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Most Discussed

More like this

Free Student Assignment Tracker Template in Google Sheets

Keeping track of assignments doesn't have to be stressful. That's why I created this...

How to Use the SHEET and SHEETS Functions in Google Sheets

The SHEET and SHEETS functions let you retrieve information about worksheets in a Google...

How to Create a Self-Healing Table of Contents in Google Sheets

A table of contents makes navigating large Google Sheets workbooks much easier. However, a...

11 COMMENTS

  1. Thank you for the tutorial. In your example, the field name is one word (i.e., “Attempt”). How do you address it when you have multiple words for the field name, for instance, “Material name” or “Number of units”? Range reference did not work for me. Thanks.

  2. Hi Prashanth,

    This is very helpful for me as well – many thanks.

    i) I have to use a syntax with “;” instead of “,”, maybe because the sheet settings are “Locale = France” (this might address the remark made by nomwoyi Kunde on March 18, 2022).

    ii) To EXCLUDE “2nd” and “3rd” attempts in the Pivot Table, I have to use the “FALSE” results of the regex (Filter applied to the “Attempt” column), i.e.:

    =regexmatch(Attempt; "2nd|3rd") = FALSE

    It works like a charm!

    Best regards,

  3. Hello,

    I’m following all the steps to use the custom filter, but it isn’t working.

    Does the datasheet and pivot table have to be on the same page?

  4. Hi Prashanth,

    This is very helpful – thanks.

    Is there a way I can combine True and False in the same regexmatch formula? e.g. include “software” and exclude “SDR”

    Thanks.
    Ami

    • Hi, Ami Shimkin,

      I may require an example to know what you are trying to do. From your question, I think FILTER may help.

      Please feel free to share an example sheet link in the “Reply”.

  5. Thanx for the reply. In my case, the data is on a different sheet so this won’t work.

    I understand as of now it is probably not possible even with a script as filter views are not called through scripts.

    I have already put a feature request many a time but so far it is not implemented.

    But thanx anyway.

    And you are really doing a good job.

  6. I follow your post very diligently and find them very informative. I use the pivot table very extensively in my work.

    I request if you can develop some script / some roundabout method to drill down to the filtered source data directly from the pivot table it would be a great help.

    Presently the native feature creates a new sheet that is not of much use.

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.