Most spreadsheet workflows break down because teams copy-paste rows manually between tabs every week. Two functions in Google Sheets—QUERY and XLOOKUP—eliminate 90% of manual filtering, pivot rebuilds, and fragile VLOOKUP column-index bugs.
1. Using QUERY Like SQL Inside Google Sheets
QUERY lets you filter, sort, aggregate, and rename columns from any range using Google Visualization Query Language. Its basic signature is:
=QUERY(data_range, "SQL_like_query", header_rows)
Filtering & Sorting Active Records
Suppose Orders!A1:E500 has columns Date (A), Client (B), Plan (C), Amount (D), Status (E). Pull only paid orders sorted highest first:
=QUERY(Orders!A1:E500, "SELECT A, B, D WHERE E = 'Paid' ORDER BY D DESC", 1)
Summarizing Revenue by Plan with GROUP BY
Instead of building a separate pivot table that needs manual refreshing, aggregate dynamically:
=QUERY(Orders!A1:E500, "SELECT C, COUNT(B), SUM(D) WHERE E = 'Paid' GROUP BY C ORDER BY SUM(D) DESC LABEL COUNT(B) 'Orders', SUM(D) 'Revenue'", 1)
Handling Date Filters Correctly (Most Common Mistake)
Writing WHERE A >= '2026-01-01' fails in QUERY because date columns require the date keyword:
=QUERY(Orders!A1:E500, "SELECT A, B, D WHERE A >= date '2026-01-01' AND E = 'Paid'", 1)
If referencing a start date stored in cell G1:
=QUERY(Orders!A1:E500, "SELECT A, B, D WHERE A >= date '" & TEXT(G1, "yyyy-mm-dd") & "'", 1)
2. Replacing Fragile VLOOKUPs with XLOOKUP
VLOOKUP breaks whenever someone inserts a column or needs to look left. XLOOKUP solves both problems and includes a built-in fallback value without wrapping in IFERROR:
=XLOOKUP(search_key, lookup_range, result_range, [missing_value])
Practical Example
Look up a customer’s tier from Accounts!B:B by matching their email in Accounts!D:D (even though column B sits to the left of column D):
=XLOOKUP(A2, Accounts!D:D, Accounts!B:B, "Not Found")
Comparing QUERY vs XLOOKUP
| Task | Best Function | Why |
|---|---|---|
| Pull multi-row filtered tables or summaries | QUERY |
Supports WHERE, GROUP BY, and ORDER BY in one formula |
| Match single ID/email to another tab’s column | XLOOKUP |
Works left or right, immune to inserted columns |
| Sum/count with simple cell criteria | SUMIFS / COUNTIFS |
Faster to read for single scalar KPIs |
Common Formula Errors & Quick Fixes
#VALUE! Unable to parse query string: Usually caused by mismatched single quotes around text values, missing thedatekeyword before dates, or referencing column names (A, B) when the input range comes from another formula (useCol1, Col2instead ofA, Bwhen querying arrays like{Tab1!A:D; Tab2!A:D}!).QUERYmixes numbers and text in one column:QUERYignores the minority data type in mixed-type columns. Ensure IDs or numbers stay formatted consistently across the entire column.