Sub topic 10
Partial text matches with wildcards
Assume you can enter formulas in Google Sheets, use ranges such as A2:A100, and distinguish text, numbers, and dates. This chapter uses a table with these columns:
| Column | Meaning |
|---|---|
| A | Region |
| B | Product |
| C | Date |
| D | Units |
| E | Revenue |
A wildcard is a special character in a text criterion. It lets a formula match a pattern instead of one exact value. * matches any number of characters, including zero characters. ? matches exactly one character. Use ~ before a wildcard when you want to match the literal character.
Match text that starts or ends with a pattern
To count products whose names start with Wid, place an asterisk after the text:
=COUNTIFS(B2:B100, "Wid*")This can match Widget, Wide Case, and Wid, but not Gadget. The formula counts matching cells in column B.
To sum revenue for the same products, use SUMIFS. Its first argument is the range to sum:
=SUMIFS(E2:E100, B2:B100, "Wid*")The criterion "Wid*" means “starts with Wid, followed by any text.” A wildcard criterion can also appear at the end of a pattern:
=COUNTIFS(B2:B100, "*case")This matches product names that end with case, such as Phone Case and Wide Case.
To match text containing a pattern anywhere, put an asterisk on both sides:
=COUNTIFS(B2:B100, "*pro*")This matches names such as Pro Tablet, Laptop Pro, and Professional Kit.
Match one unknown character
A question mark represents exactly one character. For example:
=COUNTIFS(B2:B100, "A??-100")This matches ABC-100 and AXY-100, but not AB-100 or ABCD-100. The two question marks require exactly two characters between A and -100.
Wildcards are generally used for text matching. They are not a substitute for numeric comparisons such as ">=10".
Combine wildcards with other conditions
Each criteria pair in COUNTIFS, SUMIFS, or AVERAGEIFS must be true. For example, this counts products beginning with Wid in the West region:
=COUNTIFS(A2:A100, "West", B2:B100, "Wid*")The formula applies AND logic:
- The Region cell must equal
West. - The Product cell must start with
Wid.
You can also average revenue for those rows:
=AVERAGEIFS(E2:E100, A2:A100, "West", B2:B100, "Wid*")The average includes only revenue cells from rows meeting both conditions.
Match a literal wildcard
If a product name actually contains an asterisk, escape it with a tilde. This criterion searches for text ending with a literal *:
=COUNTIFS(B2:B100, "*~*")The first * allows any preceding text. The ~* means “a literal asterisk.”
The same escape rule applies to a literal question mark: use ~?.
When patterns become complex, consider FILTER, QUERY, or regular expressions. Wildcards are convenient for simple starts-with, ends-with, contains, and one-character patterns.
Exercise
Write a formula that sums Revenue for products containing the text "kit" anywhere in the name.
Show answer
=SUMIFS(E2:E100, B2:B100, "kit")