Google Sheets QUERY and FILTER are two powerful functions that let you pull and reshape data from a range, but they work differently: FILTER returns rows that meet simple conditions using standard spreadsheet logic, while QUERY uses a SQL-like language for more complex operations like sorting, grouping, and aggregating. In short, choose FILTER for quick, straightforward row filtering and QUERY when you need advanced data manipulation.
What Is FILTER in Google Sheets?
FILTER is a native Google Sheets function that returns only the rows from a range that satisfy one or more conditions. Its syntax is:
=FILTER(range, condition1, [condition2, ...])
Each condition is an array of TRUE/FALSE values, usually created by comparing a column to a value. For example, with a list of sales in A2:B20 (items in A, amounts in B), this formula returns only rows where the amount is greater than 100:
=FILTER(A2:B20, B2:B20>100)
You can combine multiple conditions with multiplication (AND) or addition (OR). For instance, to get rows where the item is “Widget” and the amount is over 100:
=FILTER(A2:B20, (A2:A20="Widget")*(B2:B20>100))
FILTER is dynamic—if the source data changes, the result updates automatically. It also works well with other functions like SORT and UNIQUE.
What Is QUERY in Google Sheets?
QUERY is a more advanced function that uses a pseudo-SQL syntax to select, filter, sort, group, and pivot data. Its basic syntax is:
=QUERY(data, query_string, [headers])
For example, to get all rows from A2:B20 where column B is greater than 100, you write:
=QUERY(A2:B20, "SELECT * WHERE B > 100", 1)
The third argument (1) tells Sheets that the first row contains headers. QUERY supports clauses like SELECT, WHERE, ORDER BY, GROUP BY, PIVOT, LIMIT, and LABEL. It can also perform aggregate functions like SUM, AVG, COUNT, and MAX.
For instance, to sum sales by item:
=QUERY(A2:B20, "SELECT A, SUM(B) GROUP BY A LABEL SUM(B) 'Total'", 1)
QUERY is extremely flexible but has a learning curve because of its SQL-like syntax.
Key Differences Between QUERY and FILTER
While both functions return subsets of data, they differ in several important ways:
- Syntax complexity: FILTER uses standard spreadsheet logic (comparisons, AND/OR), while QUERY uses a text-based query language.
- Capabilities: QUERY can sort, group, aggregate, and pivot data; FILTER only filters rows—it cannot reorder or summarize.
- Performance: For very large datasets, QUERY can be more efficient because it processes data in a single pass, but FILTER is often faster for simple filters on small ranges.
- Error handling: FILTER returns a #N/A error if no rows match; QUERY returns an empty result or an error if the query is invalid.
- Output shape: FILTER always returns a range of the same width as the input; QUERY can return a different number of columns (e.g., when using SELECT with specific columns or aggregations).
How to Choose Between QUERY and FILTER
Use FILTER when:
- You need a simple filter based on one or a few conditions.
- You want to combine the result with other functions like
SORTorUNIQUE. - You prefer a more readable formula that doesn’t require learning SQL syntax.
Use QUERY when:
- You need to sort the output in a specific order (e.g.,
ORDER BY). - You need to aggregate data (sums, counts, averages) by category.
- You want to pivot data to create a summary table.
- You need to limit the number of rows returned (
LIMIT). - You are comfortable with SQL-like syntax or willing to learn it.
For example, if you just want to see all orders above $500, FILTER is simpler. But if you want a summary of total sales by region, QUERY is the right tool.
Common Problems and Solutions
Both functions can throw errors if not used correctly. Here are frequent issues and fixes:
- #VALUE! error in FILTER: This happens when the conditions are not arrays of the same size as the range. Make sure each condition references a column of the same length.
- #N/A error in FILTER: Occurs when no rows match. Wrap the formula in
IFERRORto show a custom message, e.g.,=IFERROR(FILTER(...), "No matches"). - QUERY returns #REF!: Often due to a missing header argument or incorrect column references. Check that the data range includes headers and that you pass the correct
headersparameter. - QUERY syntax errors: Common mistakes include using single quotes instead of double quotes for strings, forgetting to escape apostrophes (use double quotes and double the quote), or using column letters instead of column references (in QUERY, columns are referred to as A, B, C, etc., but only in the SELECT clause—not in the data range).
- QUERY ignores blank cells: By default, QUERY ignores rows where the selected column is blank. To include them, use
WHERE A IS NOT NULLorWHERE A <> "".
QUERY vs FILTER in Excel
Excel does not have a QUERY function. The closest equivalent is FILTER (available in Excel 365 and Excel 2021) and the legacy Advanced Filter feature. Excel’s FILTER works similarly to Google Sheets’ FILTER, but its syntax uses commas and does not require the multiplication trick for AND—you can use * or AND in some contexts. For advanced data manipulation, Excel users often use Power Query (Get & Transform) or pivot tables, which offer similar capabilities to Google Sheets’ QUERY.
If you are migrating from Google Sheets to Excel, you’ll need to replace QUERY with a combination of Excel functions like FILTER, SORT, UNIQUE, and SUMIFS, or use a pivot table for aggregation.
Frequently Asked Questions
Can I use QUERY and FILTER together?
Yes, you can nest them. For example, you can use FILTER inside QUERY‘s data range to pre-filter rows, or use QUERY inside FILTER as a condition. However, it’s often simpler to use one or the other. If you need to filter and then sort, you can wrap a FILTER in SORT, or use QUERY’s ORDER BY.
Why does my QUERY return a header row that I don’t want?
If your data range includes headers, you need to specify the headers argument (e.g., 1). If you don’t want the header in the output, you can use LABEL to rename it or set headers to 0 and manually handle column names. Alternatively, use SELECT * and then delete the header row in the output range.
How do I filter by date in QUERY?
Dates in QUERY must be formatted as ‘yyyy-mm-dd’ and enclosed in single quotes. For example, to filter for dates after January 1, 2023, use WHERE A > DATE '2023-01-01'. If your dates are in a column with a date format, you can also use the DATE function: WHERE A > DATE '2023-01-01' works. Alternatively, you can use WHERE A > DATE(2023,1,1).
Can I use QUERY to combine data from multiple sheets?
Yes, you can use QUERY with the {} array syntax to combine ranges from different sheets. For example, =QUERY({Sheet1!A2:B; Sheet2!A2:B}, "SELECT * WHERE Col2 > 100", 0). Note that in the array, columns are referenced as Col1, Col2, etc., not by letters.
What is the maximum number of rows QUERY can handle?
Google Sheets has a limit of 10,000 cells per formula result, but QUERY can process more rows in the source data. However, if the output exceeds 10,000 cells, you’ll get a #REF! error. For larger datasets, consider using Google Sheets’ built-in pivot tables or BigQuery.
Is FILTER faster than QUERY for large datasets?
For simple filters, FILTER is often faster because it’s a native function optimized for that task. QUERY has more overhead due to parsing the query string. However, for complex operations like grouping and sorting, QUERY may be more efficient than combining multiple functions. Performance also depends on the size of your data and your internet connection.
Related
- JS Random Number 1-5: Simple Code & How It Works
- Final Grades and General Average in Excel
- Free Online Data Entry Software: Real Options for 2025
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Google Sheets Freeze Rows Shortcut and Menu StepsGoogle Sheets has no dedicated keyboard shortcut that immediately freezes rows. In a web browser, use View >…
- Can Excel Slicers Connect to Multiple Tables Directly?In Excel, a slicer added to a regular Table filters that Table; it does not directly control other…
- How to Sort by Date in Google SheetsTo sort dates in Google Sheets, select the entire table, choose Data > Sort range > Advanced range…
- Use Power Query to Merge Excel Files: A Practical GuideIn Excel for Microsoft 365 on Windows, go to Data > Get Data > From File > From…
- Excel Merge Cells Shortcut: Keys and TipsIn Excel for Microsoft 365 on Windows, select the cells and press Alt, H, M, C in sequence…
- Excel Insert Row Below a Selected Row: Quick StepsTo insert a worksheet row below the row you selected in Excel, select the row header immediately underneath…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.