Data analysts often struggle when XLOOKUP retrieves multiple vertical rows of data that must be aligned horizontally. Just as organizations secure resources from standard funding sources to fuel operations, Excel professionals rely on robust formulas to streamline reporting. Combining TRANSPOSE with XLOOKUP grants users absolute control over data layout, instantly reorienting multi-row outputs.
Under the stipulation that this technique requires Excel 365 or Excel 2021 for dynamic array compatibility, you can easily pivot vertical datasets-such as quarterly regional sales-into clean, horizontal rows. Below, we detail the exact formula architecture to implement this solution.
Excel's XLOOKUP function has revolutionized the way we search and retrieve data, effectively rendering VLOOKUP, HLOOKUP, and even traditional INDEX/MATCH combinations obsolete in many scenarios. One of XLOOKUP's most powerful features is its ability to return entire rows, columns, or multi-cell arrays instead of just a single value.
However, retrieved data isn't always structured the way you need it for your reports or dashboards. Often, you will retrieve a horizontal row of data that you want to display vertically, or retrieve multiple rows of data that need to be flipped. In this comprehensive guide, we will explore how to transpose XLOOKUP results when dealing with single and multiple rows, utilizing TRANSPOSE and other dynamic array functions like TOROW and TOCOL.
Before diving into complex multi-row scenarios, let's briefly look at how these two functions interact. XLOOKUP searches a range or an array and returns an item corresponding to the first match it finds. If the return range spans multiple columns, XLOOKUP will "spill" those columns horizontally.
The TRANSPOSE function, on the other hand, shifts the orientation of a given range or array. It turns vertical ranges into horizontal ranges, and horizontal ranges into vertical ones. By nesting XLOOKUP inside TRANSPOSE, we can dynamically change the orientation of our lookup results on the fly.
=TRANSPOSE(XLOOKUP(lookup_value, lookup_array, return_array))
Imagine you have a dataset containing employee names and their quarterly sales figures structured horizontally:
| Employee (Col A) | Q1 (Col B) | Q2 (Col C) | Q3 (Col D) | Q4 (Col E) |
|---|---|---|---|---|
| John Doe | $12,000 | $15,000 | $14,500 | $18,000 |
| Jane Smith | $16,500 | $17,000 | $19,000 | $21,000 |
If you want to look up "John Doe" and display his quarterly figures vertically in a column instead of a row, your formula would look like this:
=TRANSPOSE(XLOOKUP("John Doe", A2:A3, B2:E3))
How it works:
XLOOKUP("John Doe", A2:A3, B2:E3) locates "John Doe" in column A and returns his corresponding values from columns B through E as a horizontal array: {"$12,000", "$15,000", "$14,500", "$18,000"}.TRANSPOSE function takes this horizontal array and pivots it into a vertical array, spilling down four consecutive cells in a single column.The real challenge arises when you want to look up multiple keys simultaneously (e.g., retrieving data for both John Doe and Jane Smith) and transpose the resulting multi-row matrix.
Let's say your lookup criteria is an array of names: {"John Doe"; "Jane Smith"}. If you execute a standard XLOOKUP with multiple lookup values, Excel will return a 2D array (2 rows by 4 columns):
=XLOOKUP(G2:G3, A2:A3, B2:E3)
(Assuming G2 contains "John Doe" and G3 contains "Jane Smith")
This will output a 2x4 grid. If you wrap this entire expression in TRANSPOSE:
=TRANSPOSE(XLOOKUP(G2:G3, A2:A3, B2:E3))
Excel will pivot the entire 2D matrix. What was a 2-row, 4-column block of data will instantly become a 4-row, 2-column block of data. The columns will now represent the individuals (John Doe in the first column, Jane Smith in the second), and the rows will represent the quarters (Q1 through Q4 vertically).
| Quarterly Metrics | John Doe (Spilled Col 1) | Jane Smith (Spilled Col 2) |
|---|---|---|
| Q1 | $12,000 | $16,500 |
| Q2 | $15,000 | $17,000 |
| Q3 | $14,500 | $19,000 |
| Q4 | $18,000 | $21,000 |
Sometimes, transposing a 2D grid into another 2D grid isn't what you want. You might want to take multiple rows of looked-up data and stack them all into a single, continuous vertical column. For instance, listing all of John's quarterly figures followed immediately by all of Jane's quarterly figures.
In modern Excel (Office 365 and Excel 2021+), we can combine XLOOKUP with the powerful TOCOL (To Column) or TOROW (To Row) functions to achieve this seamlessly.
To stack all quarterly sales of searched employees into a single column, use:
=TOCOL(XLOOKUP(G2:G3, A2:A3, B2:E3))
By default, TOCOL scans the retrieved 2D array row-by-row. This means it will output John's Q1, Q2, Q3, Q4, followed by Jane's Q1, Q2, Q3, Q4.
If you prefer to scan column-by-column (grouping all Q1s together, then all Q2s), you can set the third argument of TOCOL (scan_by_column) to TRUE:
=TOCOL(XLOOKUP(G2:G3, A2:A3, B2:E3), , TRUE)
When working with nested array formulas, errors can break your entire spilled range. If one of your lookup values is not found, XLOOKUP will return an #N/A error by default. If this happens inside a TRANSPOSE or TOCOL function, the entire output range will fail and show errors.
Always define the fourth argument of XLOOKUP to handle missing keys gracefully. Instead of letting it throw an error, return an empty string or a placeholder:
=TRANSPOSE(XLOOKUP(G2:G3, A2:A3, B2:E3, "Not Found"))
If your source table contains empty cells, XLOOKUP will return 0 for those cells. To keep them completely blank in your transposed layout, you can append an empty string to the formula:
=TRANSPOSE(XLOOKUP(G2:G3, A2:A3, B2:E3, "") & "")
Note: Concatenating with an empty string converts numbers to text, so use this option carefully if you plan to perform subsequent math calculations on the transposed results.
Because the transposed XLOOKUP formula outputs a dynamic array, it requires empty space below and to the right of the formula cell to spill its results. If there is any existing data, text, or even merged cells in the way, Excel will return a #SPILL! error.
To resolve this: Select the cell with the error, look at the dashed blue border indicating the intended spill range, and clear any blocking content within that area. Excel will instantly populate the values once the path is clear.
Combining XLOOKUP with transposing functions allows you to build highly dynamic and responsive spreadsheets. Whether you are performing a simple pivot of a single row using TRANSPOSE(XLOOKUP(...)), reshaping multi-row search queries, or flattening data layouts with TOCOL, these formulas ensure that your reports remain automated and clean. As your source data updates or expands, your transposed lookup lists will adjust automatically, saving you hours of manual copy-pasting.
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.