The direct answer: in Google Sheets Query, you filter out empty cells with where A is not null (for blank cells) or where A is not null and A <> '' (to also exclude cells containing only an empty string). This works in the QUERY function’s SQL-like syntax, and it is the most reliable way to remove blank rows from a dataset.
Why “Is Not Null” Matters in Query
Google Sheets’ QUERY function uses a Google Visualization API query language that resembles SQL. In that language, null represents a missing value—a truly empty cell. However, a cell can look empty but actually contain an empty string (''), which is common when a formula like =IF(A1="","",B1) returns "". The is not null clause only removes cells that are truly blank; it does not remove cells with an empty string. To handle both, you combine two conditions.
Basic Syntax and Examples
Assume you have a dataset in columns A and B, with rows 1 to 10, where column A has some blank cells. The basic formula to return all rows where column A is not blank is:
=QUERY(A1:B10, "select * where A is not null", 1)
This returns all rows where A has a value. If you also want to exclude cells that contain an empty string (e.g., from a formula), use:
=QUERY(A1:B10, "select * where A is not null and A <> ''", 1)
Note the two single quotes inside the double-quoted string—this is the literal empty string. The 1 at the end tells Query that the first row contains headers, so it is not filtered out.
Common Pitfalls and Misconceptions
A frequent mistake is using where A <> "" alone. That works for empty strings but not for truly blank cells. Another pitfall is using where A is not null on a column that contains spaces. A cell with a single space is not null and not an empty string—it will pass both filters. To remove cells with only whitespace, you need to trim first, for example:
=QUERY(ARRAYFORMULA(TRIM(A1:A10)), "select * where Col1 is not null and Col1 <> ''", 1)
But note that TRIM changes the column reference to Col1 because it is an array. This is a common source of confusion.
Alternatives to Query for Filtering Blanks
If you are not wedded to Query, you have simpler options:
- FILTER function:
=FILTER(A1:B10, A1:A10 <> "")removes rows where A is blank or contains an empty string. It is more intuitive but does not handle whitespace-only cells. - Data menu: Select the column, then Data > Create a filter, and uncheck “Blanks” in the filter dropdown. This is manual but quick.
- Sort and delete: Sort by the column, then delete blank rows manually. Not recommended for large datasets.
Query is more powerful when you need to aggregate or join data, but for simple blank removal, FILTER is often easier to read.
How to Use Query with Multiple Columns and Conditions
You can combine is not null with other conditions. For example, to get rows where column A is not blank and column B is greater than 100:
=QUERY(A1:B10, "select * where A is not null and B > 100", 1)
You can also use or logic, but be careful with parentheses. For instance, to get rows where A is not null OR B is not null, you must wrap the conditions:
=QUERY(A1:B10, "select * where (A is not null) or (B is not null)", 1)
Without parentheses, the query may be interpreted incorrectly.
Performance and Large Datasets
Query is efficient even on large sheets, but using is not null on a full column (e.g., A:A) can slow down the sheet because it scans the entire column. It is better to limit the range to your actual data, like A1:A1000. If you have thousands of rows, consider using ARRAY_CONSTRAIN or a named range to keep the query range tight. Also, avoid using select * if you only need a few columns—specify them explicitly to reduce processing.
Differences from Excel
Excel does not have a QUERY function. The closest equivalent is the FILTER function (available in Excel 2021 and Microsoft 365) or using an Advanced Filter. In Excel, you would write =FILTER(A1:B10, A1:A10 <> "") to exclude blanks. Excel’s FILTER treats blank cells and empty strings the same way—both are excluded when you compare to "". If you need to exclude whitespace-only cells, you would use TRIM(A1:A10) <> "" inside the FILTER, but that requires an array context. In Google Sheets, the Query language is unique, so you must adapt when moving between the two applications.
Frequently Asked Questions
Does “is not null” also remove cells with a zero?
No. A cell containing the number 0 is not null—it is a valid value. The is not null clause only removes cells that are truly empty. If you want to remove zeros as well, add and A <> 0 to the query.
Why does my query return a header row even when I use “is not null”?
If you include the header row in your range and pass 1 as the third argument, Query treats the first row as headers and does not filter it out. If you do not want headers, use 0 instead, but then the first row of data will be treated as a regular row and may be filtered if it is blank.
Can I use “is not null” on a column that contains dates?
Yes. Dates are stored as numbers in Google Sheets, so a date cell is not null. The same syntax works: where A is not null. However, be aware that if you have a date formatted as text, it may not be recognized as a date in the query, but it will still be considered not null.
How do I filter out rows where a cell contains only spaces?
Use TRIM in an array formula before querying, or use a regex match. The simplest is to wrap the column in TRIM and then check for is not null and <> ''. For example: =QUERY(ARRAYFORMULA(TRIM(A1:A10)), "select * where Col1 is not null and Col1 <> ''", 1).
Is there a way to use “is not null” in a pivot table?
Pivot tables in Google Sheets have their own filter options. You can click on the row or column label, then “Filter by condition” and choose “Not empty”. That achieves the same effect without using Query.
What if I want to keep rows that are blank in one column but not in another?
Use or logic. For example, =QUERY(A1:B10, "select * where A is not null or B is not null", 1) returns rows where at least one of the two columns has a value. This is useful for finding rows that are not completely empty.
Related
- Forecast ETS Excel: How to Use It
- Data Entry Position: What It Is and What It Involves
- Table Saw Crosscut Sled: Build or Buy Guide
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Errors & fixes
- Excel Can’t Save Here Error: Causes, Fixes, and ChecksThe Excel message “You can’t save here” usually means Excel cannot write the workbook to the selected location,…
- Excel Web Formula Not Working? Causes and Fixes That WorkIn Excel for the web, a formula usually fails because it is stored as text, has a syntax…
- Excel FILTER Function Not Working? Fix Common CausesIf Excel’s FILTER function is not working, first confirm you are using Microsoft 365 or Excel 2021 or…
- Excel Column A Missing? How to Bring It BackIf column A is missing in Excel, it is usually hidden, scrolled out of view, or reduced to…
- Excel File Keeps Not Responding? Causes and FixesIf Excel says Not Responding, first wait a minute or two if the workbook is large or has…
- Excel Can’t Insert Row? Fix the Non-Empty Cells ErrorYes—Excel may refuse to insert a row when shifting cells down would push existing content or formatting past…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.