Sub topic 6
Joining ranges and skipping blanks with FILTER
This chapter assumes you can write JOIN with a delimiter and a single range, and that you know what a spilled array is. It also assumes you have used ARRAYFORMULA and IFERROR. Here you will build the pattern JOIN(delimiter, FILTER(range, condition)). It turns a column with gaps into a clean, delimited string.
What JOIN accepts
The signature is:
=JOIN(delimiter, value_or_array1, [value_or_array2, ...])The delimiter comes first, which is the reverse of what many people expect from CONCATENATE. After it you can pass any mix of single cells, ranges, array results, and literal values. JOIN flattens all of them into one list and glues the items together with the delimiter.
=JOIN(" | ", A2:A4, "extra", C2:C3)If A2:A4 holds red, green, blue and C2:C3 holds x, y, the result is:
red | green | blue | extra | x | yThree behaviors matter when you pass ranges:
- Order. A one-column range is read top to bottom. A one-row range is read left to right. A two-dimensional range such as
A2:C4is read row by row: A2, B2, C2, then A3, B3, C3, and so on. - Numbers become text.
JOINalways returns a string. The number 42 becomes"42", and you cannot add the result to anything without converting it back. - Dates lose their formatting. A date in a cell is a number underneath, and
JOINmay show you that underlying serial number instead of the formatted date. Convert dates withTEXTfirst, as shown later in this chapter.
The blank-cell problem
Real columns have gaps. Suppose A2:A8 holds this:
| Cell | Value |
|---|---|
| A2 | `apples` |
| A3 | (empty) |
| A4 | `pears` |
| A5 | `=""` (a formula that returns an empty string) |
| A6 | `plums` |
| A7 | (a single space) |
| A8 | `figs` |
There are three kinds of "blank" here, and JOIN does not treat them alike. In current Sheets a truly empty cell such as A3 is usually skipped, but an empty string from a formula (A5) or a cell containing only a space (A7) counts as a real item. Each of those items still gets a delimiter, so you see output like apples, pears, , plums, , figs. Behavior around empty cells has varied between Sheets features over time, so do not rely on it. State the filtering explicitly and the result is the same in every case.
The fix is to remove blanks before JOIN sees them.
FILTER removes the blanks
FILTER(range, condition) returns only the rows of range where the condition is TRUE. Passing a condition built from the same range keeps only non-blank values:
=JOIN(", ", FILTER(A2:A10, A2:A10<>""))Here A2:A10<>"" evaluates to an array of TRUE and FALSE values, one per cell. FILTER keeps the rows with TRUE, and JOIN receives a list with no gaps. Both a truly empty cell and a formula that returns "" compare equal to "", so both are removed.
Cells that only look blank
The cell A7 above contains a space. It is not equal to "", so the simple filter keeps it. Trim before comparing:
=JOIN(", ", FILTER(A2:A10, ARRAYFORMULA(TRIM(A2:A10))<>""))The FILTER still returns the original values from A2:A10. Only the test uses the trimmed copy. If you also want the kept values trimmed, apply TRIM to the output:
=JOIN(", ", ARRAYFORMULA(TRIM(FILTER(A2:A10, ARRAYFORMULA(TRIM(A2:A10))<>""))))This matters for data pasted from web pages or exports, where stray spaces and non-breaking spaces are common. TRIM does not remove a non-breaking space (character 160). If a cell still passes the filter after trimming, replace it first with SUBSTITUTE(A2:A10, CHAR(160), " ").
Filtering on a different column
The condition does not have to test the range you are joining. Any array of the same height works, which makes JOIN(FILTER(...)) a text version of a lookup that returns many matches.
Suppose column A holds task names and column B holds a status:
| Row | A (task) | B (status) |
|---|---|---|
| 2 | Write intro | Done |
| 3 | Draft diagram | Open |
| 4 | Review code | Open |
| 5 | Publish | Blocked |
This formula lists every open task in one cell:
=JOIN(", ", FILTER(A2:A5, B2:B5="Open"))The result is Draft diagram, Review code.
You can combine conditions. Multiply arrays for AND, add them for OR:
=JOIN(", ", FILTER(A2:A5, (B2:B5="Open") + (B2:B5="Blocked")))Here + acts as OR, because a row that is TRUE for either test sums to 1, and FILTER treats any non-zero value as TRUE. To require both conditions, use * instead.
You can also wrap the filtered result in other array functions before joining. SORT and UNIQUE are the usual choices:
=JOIN(", ", SORT(UNIQUE(FILTER(A2:A100, A2:A100<>""))))This produces an alphabetical list of distinct non-blank values.
When nothing matches
If no row passes the condition, FILTER returns #N/A rather than an empty list, and JOIN passes that error through. A project with no open tasks therefore shows #N/A instead of an empty cell. Wrap the whole formula:
=IFERROR(JOIN(", ", FILTER(A2:A5, B2:B5="Open")), "")Be aware that IFERROR also hides every other error, such as a mistyped range size. While you are building the formula, leave IFERROR off. Add it once the formula works on data that has matches.
Converting values before joining
Because JOIN stringifies whatever it receives, format values first when appearance matters. Use ARRAYFORMULA so TEXT applies to every cell:
=JOIN(", ", ARRAYFORMULA(TEXT(FILTER(C2:C10, C2:C10<>""), "yyyy-mm-dd")))This keeps only the filled dates, formats each as 2026-11-27, and joins them. The same approach works for currency or percentages, using a format such as "0.00" or "0%".
Joining each row separately
JOIN returns one string for everything you give it. It does not process a range one row at a time, and wrapping it in ARRAYFORMULA does not change that. To build one string per row, use BYROW with LAMBDA:
=BYROW(A2:D10, LAMBDA(r, IFERROR(JOIN(", ", FILTER(r, r<>"")), "")))For each row r of A2:D10, the formula keeps the non-blank cells and joins them. The IFERROR handles rows that are completely empty, where FILTER has nothing to return. The result is a column of strings with one entry per input row.
Round trip: SPLIT, clean, JOIN
JOIN is the inverse of SPLIT, so the two combine into a cleanup pass. Given a cell like red ; green;;blue in A2:
=JOIN(", ", ARRAYFORMULA(TRIM(SPLIT(A2, ";"))))SPLIT breaks the text at semicolons and drops the empty piece between ;;. TRIM removes the stray spaces from each piece. JOIN reassembles them as red, green, blue. To guard against pieces that are only spaces, add a FILTER in the middle:
=JOIN(", ", FILTER(ARRAYFORMULA(TRIM(SPLIT(A2, ";"))), ARRAYFORMULA(TRIM(SPLIT(A2, ";")))<>""))This is long because the array appears twice. Chapter 12 shows how to keep formulas like this readable.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Output has doubled delimiters such as `a, , b` | Empty strings or space-only cells are being kept | Filter with `<>""`, and use `TRIM` in the test for space-only cells |
| `#N/A` in the result cell | `FILTER` matched no rows | Wrap in `IFERROR(..., "")` once the formula works |
| Error about mismatched sizes | Condition range and filtered range differ in height | Make both ranges cover the same rows |
| Dates appear as numbers like `46353` | `JOIN` received the underlying serial value | Convert with `TEXT(..., "yyyy-mm-dd")` inside `ARRAYFORMULA` |
| One string for the whole table instead of one per row | `JOIN` does not work row by row | Use `BYROW` with `LAMBDA` |
| Delimiter appears as the first item | Arguments in the wrong order | Put the delimiter first |
Exercise
Column A (A2:A20) holds tags, some cells empty and some containing only spaces. Column B holds a status, either "Live" or "Draft". Write one formula that returns the tags whose status is "Live", separated by a semicolon and a space. It must skip empty and space-only tag cells. It must show an empty cell, not an error, when no tag qualifies.
Show answer
=IFERROR(JOIN("; ", FILTER(A2:A20, (B2:B20="Live") * (ARRAYFORMULA(TRIM(A2:A20))<>""))), "") The two tests are multiplied, so a row is kept only when both are TRUE. TRIM inside ARRAYFORMULA makes space-only cells compare equal to "" and drop out. If nothing passes, FILTER returns #N/A, and IFERROR turns that into an empty string.
Exercise
A2:D10 holds up to four phone numbers per row, with gaps. You write =ARRAYFORMULA(JOIN(" / ", A2:D10)) and get one long string instead of one string per row. Why, and what formula fixes it?
Show answer
JOIN always produces a single string from everything it receives, and ARRAYFORMULA does not make it process one row at a time. Use BYROW: =BYROW(A2:D10, LAMBDA(r, IFERROR(JOIN(" / ", FILTER(r, r<>"")), ""))). The FILTER drops blanks within each row, and IFERROR covers rows with no numbers at all.