Sub topic 16
When to use something else: regex, FILTER, QUERY, pivot tables
Assume you can enter formulas, use ranges such as A2:E100, and distinguish text, numbers, and dates. SUMIFS, COUNTIFS, and AVERAGEIFS work well when you need one result from rows that meet clear conditions. They become less convenient when you need flexible text patterns, a returned list of rows, grouped summaries, or interactive exploration.
Use regex for complex text patterns
A regular expression, or regex, is a pattern language for finding text. SUMIFS supports only simple wildcards:
*matches any number of characters.?matches exactly one character.~treats the next wildcard as a literal character.
Use REGEXMATCH when the rule is more detailed, such as “starts with Wid and ends with a number.”
=FILTER(A2:E100, REGEXMATCH(B2:B100, "^Wid.*[0-9]$"))Here, ^ means the beginning of the cell, .* means any characters, and $ means the end. Regex functions return or test text. They do not directly replace SUMIFS for numeric aggregation, so combine them with FILTER, or use a helper column.
Use FILTER when you need the matching rows
FILTER returns records instead of reducing them to one count, sum, or average. This is useful when someone needs to inspect the matching transactions.
=FILTER(A2:E100, A2:A100="West", D2:D100>=10)Each filter condition must be true for a row, so these conditions use AND logic. Add IFNA if no rows might match:
=IFNA(FILTER(A2:E100, A2:A100="West"), "No matching rows")FILTER can produce a changing-size result. Leave empty cells below and to the right of the formula so the result can expand.
Use QUERY for grouped or report-like results
QUERY uses a SQL-like language. It is useful when you want to select columns, filter rows, group by a category, and calculate several measures in one output.
=QUERY(A1:E100,
"select A, count(B), sum(E), avg(E)
where A is not null
group by A
label count(B) 'Rows', sum(E) 'Revenue', avg(E) 'Average revenue'",
1)The final 1 tells Sheets that the first row contains headers. QUERY is concise for grouped reports, but its syntax is stricter than ordinary Sheets formulas. Dates, column letters, and headers can also cause confusing errors.
Use pivot tables for interactive exploration
A pivot table groups data without requiring a formula for every result. Add Region as a row, then add Revenue as a value summarized by SUM or AVERAGE. Add filters for dates, products, or other fields.
Pivot tables are useful when the grouping changes often. They are less suitable when you need a fixed layout for a dashboard or a formula that another sheet can reference predictably.
Exercise
You need a list of West-region rows whose product name contains “wire,” regardless of capitalization. Which approach fits best?
Show answer
Use FILTER with REGEXMATCH, such as =FILTER(A2:E100, A2:A100="West", REGEXMATCH(LOWER(B2:B100), "wire")).