
π This article includes 2 downloadable practice files β
A classic request: βWhich products did the North region buy?β VLOOKUP and XLOOKUP stop at the first match, so you get βKeyboardβ and miss the other five. One formula combination fixes it and updates itself when the data changes.
In this article
Try it live in the Formula Lab β βFILTER Β· SORT Β· UNIQUEβ tab β βAll products per region in one cellβ.
The formula
=TEXTJOIN(", ", TRUE, UNIQUE(FILTER(B2:B100, A2:A100 = H2, "")))
Read it from the inside out:
- FILTER(B2:B100, A2:A100 = H2) β every product where the region equals H2.
- UNIQUE(β¦) β removes repeats, so βMouseβ appears once even if it was sold ten times.
- TEXTJOIN(“, “, TRUE, β¦) β glues the list into one cell with a comma between items; TRUE skips blanks.
The final "" in FILTER is what to return when nothing matches β without it you get #CALC!.
Variations you will actually use
| Need | Formula |
|---|---|
| Sorted AβZ | =TEXTJOIN(", ",TRUE,SORT(UNIQUE(FILTER(B2:B100,A2:A100=H2,"")))) |
| Two conditions | =TEXTJOIN(", ",TRUE,FILTER(B2:B100,(A2:A100=H2)*(C2:C100>=1000),"")) |
| One per line | =TEXTJOIN(CHAR(10),TRUE,FILTER(B2:B100,A2:A100=H2,"")) + Wrap Text on the cell |
| Count as well | =COUNTA(UNIQUE(FILTER(B2:B100,A2:A100=H2)))&" products" |
* means AND and + means OR: (A2:A100="North")+(A2:A100="East") keeps rows from either region.Older Excel (2016 and earlier)
FILTER, UNIQUE and dynamic arrays need Excel 2021 or Microsoft 365. TEXTJOIN exists from Excel 2019. For older versions a tiny custom function does the job:
Function JoinMatches(lookup As Variant, keys As Range, vals As Range, Optional sep As String = ", ") As String
Dim i As Long, out As String
For i = 1 To keys.Rows.Count
If keys.Cells(i, 1).Value = lookup Then
If InStr(sep & out & sep, sep & vals.Cells(i, 1).Value & sep) = 0 Then
out = out & IIf(out = "", "", sep) & vals.Cells(i, 1).Value
End If
End If
Next i
JoinMatches = out
End Function
' =JoinMatches(H2, A2:A100, B2:B100)
The InStr check skips duplicates, so it behaves like UNIQUE.
Where this saves real time
- A customer summary sheet: all invoice numbers per customer in one cell.
- Project trackers: every owner assigned to a project.
- SAP/Oracle exports: all cost centres that posted to an account.
Try it yourself: step by step
- Download all-matches-practice.xlsx and open the All matches sheet.
- Column B lists every product each region bought, alphabetically and without repeats, e.g. Keyboard, Monitor, Mouse, Webcam.
- Click
B2and read the formula from the inside out: FILTER β UNIQUE β SORT β TEXTJOIN. - On the Sales sheet change one rowβs Region from North to South. Both lists update instantly.
- Change the separator from
", "toCHAR(10), then turn on Wrap Text for column B to get one product per line. - Add a second condition: only products with quantity 10 or more. Replace the FILTER part with
FILTER(Sales!E2:E61,(Sales!C2:C61=A2)*(Sales!F2:F61>=10),"").
Frequently asked questions
Why do I get #CALC!?
FILTER found nothing and you did not supply the third argument. Add "" (or βNoneβ) as the last FILTER argument.
Is there a limit to how much TEXTJOIN can return?
A cell holds up to 32,767 characters; beyond that TEXTJOIN returns #VALUE!. For huge lists use a pivot table or FILTER into a column instead.
Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.
π Practice files for this article
β¬ Download all 2 files (ZIP Β· 44 KB)
- πAll-matches workbook60 sales rows + TEXTJOIN/UNIQUE/FILTER formulas per region.β¬ XLSX Β· 9 KB
- πFormula combinations practice workbook50 tasks: lookups, running totals, ranks, top-N, unique counts, FY, age, text extraction, list comparison, weighted averages, ageing, rolling totals, duplicates and working days β with automatic checks.β¬ XLSX Β· 39 KB
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time β plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul βStuck on a step? Ask a question and the AI answers using this article.