Combination

All invoices of one supplier in one cell with TEXTJOIN and FILTER

Pick the invoice numbers of one supplier with FILTER and join them into a single line with TEXTJOIN, with a message when the supplier has no invoices.

Functions used:TEXTJOINFILTERExcel 2021 or later (This combination needs Excel 2021 or later)

Difficulty rating 3 of 5

Worked example

Invoice numbers for a supplier confirmation letter

Scenario

For the year-end audit of Veldhuis Installatie BV you send confirmation letters to suppliers. The letter for supplier C2001 must list every invoice of that supplier in this extract, in one line of the letter text.

You have the purchase journal (INK) lines for November and December 2025, one per invoice, and you want the invoice numbers in a single cell instead of copying them by hand.

The data

Sheet excerpt: H2 holds the formula
RowABCDEFGHI
1RelationInvoice no.DateAmountSupplierC2001
2C200125-04123 Nov 2025€4,210.50€ 4.210,50Invoices25-0412, 25-0431, 25-0457, 25-0471=TEXTJOIN(", ", TRUE, FILTER(B2:B9, A2:A9=H1, "No invoices"))=TEXTJOIN(", "; TRUE; FILTER(B2:B9; A2:A9=H1; "No invoices"))
3C200225-041510 Nov 2025€1,890.00€ 1.890,00
4C200125-043124 Nov 2025€12,600.00€ 12.600,00
5C200325-04402 Dec 2025€760.25€ 760,25
6C200125-045715 Dec 2025€3,350.00€ 3.350,00
7C200225-046319 Dec 2025€2,480.00€ 2.480,00
8C200125-047129 Dec 2025€905.75€ 905,75
9C200325-047630 Dec 2025€5,120.00€ 5.120,00
10
Formula cell (H2)Input

Formula in H2

=TEXTJOIN(", ", TRUE, FILTER(B2:B9, A2:A9=H1, "No invoices"))
=TEXTJOIN(", "; TRUE; FILTER(B2:B9; A2:A9=H1; "No invoices"))

Result: 25-0412, 25-0431, 25-0457, 25-0471

How the pieces fit together

The formula taken apart, from the inside out. Each part can be typed into its own cell to see what it returns.

  1. =A2:A9=H1
    =A2:A9=H1

    Compares each relation code in A2:A9 with the supplier in H1 (C2001). The result is a column of eight values: TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE. Four rows belong to C2001.

  2. =FILTER(B2:B9, A2:A9=H1)
    =FILTER(B2:B9; A2:A9=H1)

    FILTER keeps the invoice numbers where the comparison is TRUE: 25-0412, 25-0431, 25-0457 and 25-0471. That is a column of four cells, still spread over four rows.

  3. =FILTER(B2:B9, A2:A9=H1, "No invoices")
    =FILTER(B2:B9; A2:A9=H1; "No invoices")

    The third argument is returned when nothing matches. For C2001 it is not used and the four invoice numbers come back. For a code such as C2009, which is not in the list, you would see the text instead of the #CALC! error.

  4. =TEXTJOIN(", ", TRUE, FILTER(B2:B9, A2:A9=H1, "No invoices"))
    =TEXTJOIN(", "; TRUE; FILTER(B2:B9; A2:A9=H1; "No invoices"))

    TEXTJOIN glues the four invoice numbers together with a comma and a space between them: 25-0412, 25-0431, 25-0457, 25-0471. If FILTER returns the message, TEXTJOIN returns that text.

Step by step

  1. A2:A9=H1 compares the eight relation codes with C2001: TRUE at positions 1, 3, 5 and 7 of the list, FALSE in the other four.
  2. FILTER(B2:B9, ...) keeps the invoice numbers at those positions: 25-0412, 25-0431, 25-0457, 25-0471. Four of eight rows remain.
  3. Because there are matches, the third argument ("No invoices") is not used.
  4. TEXTJOIN(", ", TRUE, ...) puts ", " between the four values: 25-0412, 25-0431, 25-0457, 25-0471.
  5. Check: 4 invoice numbers of 7 characters plus 3 separators of 2 characters is 28 + 6 = 34 characters in cell H2.

Why it works

FILTER does the selecting and returns the matches as a list; TEXTJOIN takes a whole list as one argument and turns it into text. Because FILTER sits inside TEXTJOIN, you never need helper cells.

The third argument of FILTER also covers the empty case, so the letter never shows an error for a supplier without invoices.

Watch out for

  • If the supplier code in H1 has a trailing space ("C2001 " copied from a mail), nothing matches and you see the message. Clean the input with TRIM or retype it.
  • The result is one piece of text. A cell holds at most 32,76732.767 characters, so when the joined result would exceed that, TEXTJOIN returns #VALUE! instead of a shortened text. For letters this is rarely a problem, but check the count for large suppliers.
  • The order follows the data, not the invoice number. If the purchase journal is not sorted by invoice number, the line in the letter is not either. Wrap FILTER in SORT when the order matters.

Variations

=TEXTJOIN(", ", TRUE, IF(A2:A9=H1, B2:B9, ""))
=TEXTJOIN(", "; TRUE; IF(A2:A9=H1; B2:B9; ""))

The older construction without FILTER: IF returns the invoice number for the matching rows and an empty text for the others, and TRUE tells TEXTJOIN to skip the empty ones. Same result, but no message for a supplier without invoices (the cell is empty), and in versions before Excel 365 it must be entered with Ctrl+Shift+Enter.

=TEXTJOIN(", ", TRUE, SORT(FILTER(B2:B9, A2:A9=H1, "No invoices")))
=TEXTJOIN(", "; TRUE; SORT(FILTER(B2:B9; A2:A9=H1; "No invoices")))

SORT puts the invoice numbers in ascending order before they are joined. The data is already in that order, so the result is the same here; it makes the letter safe when the export is sorted by date or by amount.

All combinations