Google Sheets QUERY Function Complete Guide 2027
By Tuân HoangMarch 29, 202612 min read
What is QUERY?
QUERY lets you analyze data in Google Sheets using SQL-like syntax. It can filter rows, select specific columns, sort, group, aggregate — all in a single formula. It is the most powerful analytical function in Google Sheets.
QUERY Basic Syntax
=QUERY(data, query_string, [headers])
data: range to query (e.g., A1:F1000 or Sheet1!A:F)
query_string: SQL-like query in double quotes
headers: number of header rows (usually 1)Essential QUERY Examples
1. Select all columns
=QUERY(Sales!A:F, "SELECT *", 1)2. Filter by condition
=QUERY(Sales!A:F, "SELECT A,B,E WHERE C='Hanoi'", 1)
Filter by date range:
=QUERY(Sales!A:F, "SELECT * WHERE A >= date '2027-01-01'", 1)3. Aggregate with GROUP BY
Revenue by sales rep:
=QUERY(Sales!A:F, "SELECT C, SUM(E) GROUP BY C ORDER BY SUM(E) DESC", 1)
Monthly revenue:
=QUERY(Sales!A:F, "SELECT MONTH(A), SUM(E) GROUP BY MONTH(A)", 1)4. Dynamic filter using cell reference
=QUERY(Sales!A:F, "SELECT * WHERE C='"&B1&"'", 1)
Where B1 contains the city/rep name to filter byQUERY vs SUMIFS: When to Use Each
- SUMIFS: Simple aggregation into a single cell. Faster for basic sums.
- QUERY: Complex multi-column analysis, sorting, or when you need multiple result rows.
Common QUERY Errors
- Error: Unable to parse query string — check quote types (use straight quotes, not curly). String values need single quotes inside the query.
- Wrong column letters — QUERY uses A, B, C based on the source range position, not sheet column letters.
- Date filter not working — dates need the format: date 'YYYY-MM-DD'
FAQ
Can QUERY handle data from multiple sheets?
Yes, combine with IMPORTRANGE or {Sheet1!A:F; Sheet2!A:F} to query multiple ranges as one dataset. Just ensure all ranges have the same column structure.
Bài viết này cũng có bản tiếng Việt
Try SheetStore for Google Sheets
Management software built on Google Sheets — from $29 one-time
View Pricing