Manually consolidating fragmented row data, such as multiple funding streams assigned to a single project ID, is incredibly tedious and error-prone. While standard funding sources like venture capital or traditional loans are typically tracked individually, managing diverse grant portfolios requires unified oversight. Because grants offer non-dilutive capital that accelerates growth, aggregating this specific financial data is crucial. However, a key stipulation is that legacy Excel versions lack the dynamic array capabilities required for modern concatenation. For instance, when tracking complex SBIR grants, manual workarounds fail. Below, we outline how to utilize the TEXTJOIN and FILTER functions to automate your reporting.
When working with flat data structures in Excel, you will frequently encounter scenarios where a single unique identifier (such as an Order ID, User ID, or Project Code) is associated with multiple rows of data. For example, an order containing several products might list each product on a separate row, repeating the Order ID.
Consolidating these repeating rows into a single summary sheet-where each unique ID has all its corresponding values concatenated into a single, comma-separated cell-is a common business reporting requirement. While older versions of Excel made this task notoriously difficult, modern versions of Excel (Excel 365, Excel 2021, and newer) provide incredibly simple dynamic formulas to handle this instantly.
In this guide, we will explore the best formulas and techniques to concatenate row values matching a specific ID, ranging from modern dynamic array formulas to backward-compatible methods for older Excel versions and Power Query.
Assume we have the following raw data table representing customer orders (Columns A and B):
| Order ID (Column A) | Product Purchased (Column B) |
|---|---|
| 1001 | Wireless Mouse |
| 1002 | Mechanical Keyboard |
| 1001 | USB-C Cable |
| 1003 | Monitor Mount |
| 1001 | HDMI Switch |
| 1002 | Desk Pad |
Our goal is to create a summary table that lists each unique Order ID and groups all associated products into a single cell, separated by commas:
| Unique ID (Column D) | Concatenated Products (Column E) |
|---|---|
| 1001 | Wireless Mouse, USB-C Cable, HDMI Switch |
| 1002 | Mechanical Keyboard, Desk Pad |
| 1003 | Monitor Mount |
If you are using Excel 365 or Excel 2021, this is the easiest, most efficient, and highly recommended formula. It combines the text-merging power of TEXTJOIN with the array-filtering capability of the FILTER function.
=TEXTJOIN(", ", TRUE, FILTER(B$2:B$7, A$2:A$7=D2))
FILTER(B$2:B$7, A$2:A$7=D2): This nested function scans the range A$2:A$7 looking for values that match the ID in D2. It returns an array of matching values from the products column B$2:B$7. For ID 1001, this returns {"Wireless Mouse";
"USB-C Cable";
"HDMI Switch"}.TEXTJOIN(", ", TRUE, ...): This function takes the array generated by the FILTER function and joins the values together.
", ") is the;
separates each value.TRUE) instructs Excel to ignore any empty cells within the matched range.Sometimes, raw data contains duplicate rows. If a customer bought two USB-C cables under the same Order ID, you might not want "USB-C Cable" to appear twice in your concatenated list. Additionally, you may want to present the items in alphabetical order.
By nesting additional dynamic array functions, we can seamlessly deduplicate and sort our output.
=TEXTJOIN(", ", TRUE, UNIQUE(FILTER(B$2:B$7, A$2:A$7=D2)))
The UNIQUE function filters out duplicate products from the array before passing them to TEXTJOIN.
=TEXTJOIN(", ", TRUE, SORT(UNIQUE(FILTER(B$2:B$7, A$2:A$7=D2))))
The SORT function arranges the unique items alphabetically (A to Z) before they are concatenated.
If you are using Excel 2019, you have access to the TEXTJOIN function, but you do not have access to the FILTER function. To achieve the same outcome, you must use a traditional array formula by pairing TEXTJOIN with an IF statement.
=TEXTJOIN(", ", TRUE, IF(A$2:A$7=D2, B$2:B$7, ""))
Because this is an legacy array formula, you cannot simply press Enter. After typing the formula into your cell, you must press Ctrl + Shift + Enter. When done correctly, Excel will automatically wrap your formula in curly braces like this: {=TEXTJOIN(", ", TRUE, IF(A$2:A$7=D2, B$2:B$7, ""))}.
The IF statement evaluates every single row in the specified range. If a row in column A matches the ID in D2, it outputs the product from column B. If it does not match, it outputs an empty string (""). The array passed to TEXTJOIN looks like this: {"Wireless Mouse"; ""; "USB-C Cable"; ""; "HDMI Switch"; ""}. Because we set the second argument of TEXTJOIN to TRUE, Excel ignores all the empty strings and concatenates only the matching products.
If you are using Excel 2016 or earlier, the TEXTJOIN function is not natively available. To accomplish this task without manually updating your sheet, you can create a Custom User Defined Function (UDF) using VBA.
Function ConcatIf(LookupRange As Range, MatchValue As Variant, TargetRange As Range, Optional;
String = ", ");
String
Dim i;
Long
Dim Result;
String
For i = 1 To LookupRange.Cells.Count
If LookupRange.Cells(i).Value = MatchValue Then
If TargetRange.Cells(i).Value <> "" Then
Result = Result & TargetRange.Cells(i).Value & Delimiter
End If
End If
Next i
' Trim trailing delimiter
If Len(Result) > 0 Then
Result = Left(Result, Len(Result) - Len(Delimiter))
End If
ConcatIf = Result
End Function
You can now use your custom function just like any native Excel formula. In cell E2, enter:
=ConcatIf(A$2:A$7, D2, B$2:B$7, ", ")
If you are working with exceptionally large datasets (tens of thousands of rows), writing complex formulas for each row can significantly slow down your workbook's performance. Power Query is Excel's built-in data transformation tool and handles group-and-concatenate tasks efficiently with zero slowdown.
"TempTable"). Click OK.Text.Combine([TempTable][Product Purchased], ", ")
"TempTable" column as it is no longer needed.Choose your solution based on your dataset size and the Excel version you or your end-users run:
| Excel Version | Best Method | Pros / Cons |
|---|---|---|
| Excel 365 / 2021 | TEXTJOIN + FILTER |
Fastest to write, dynamic, easily allows sorting/deduplication. |
| Excel 2019 | TEXTJOIN + IF (CSE Array) |
Native formula solution, but requires the CSE key combination. |
| Excel 2016 or Older | VBA (ConcatIf UDF) |
Overcomes legacy limitations, but requires saving workbook as .xlsm. |
| Any version (Large Datasets) | Power Query | Incredibly fast, handles millions of rows, handles data refreshes cleanly. |
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.