Yes, you can transpose the result of a QUERY function in Google Sheets by wrapping the entire QUERY formula in the TRANSPOSE function, like this: =TRANSPOSE(QUERY(A1:C10, "select A, sum(C) group by A")). This swaps rows and columns of the query output, turning horizontal results into vertical ones or vice versa. Below I’ll explain exactly how it works, when you’d want to use it, and common pitfalls to avoid.
What Does TRANSPOSE Do in Google Sheets?
The TRANSPOSE function in Google Sheets takes an array (a range or a formula result) and flips its orientation: rows become columns and columns become rows. For example, if you have data in A1:C3, =TRANSPOSE(A1:C3) would place that data into rows 1–3 of columns starting at the cell where you enter the formula, but with the first row of the original becoming the first column of the result, and so on.
When you combine TRANSPOSE with QUERY, you’re not just flipping a static range—you’re flipping the dynamic result of a query. This is especially useful when your QUERY returns data in a layout that doesn’t match your report’s needs. For instance, a pivot-style query often returns months as rows; transposing makes them columns.
How to Write a TRANSPOSE(QUERY()) Formula
The syntax is straightforward: =TRANSPOSE(QUERY(data, query_string, [headers])). The QUERY function runs first, producing a table of results, and then TRANSPOSE flips that table. Here’s a step-by-step example:
- Suppose you have sales data in A1:C10, with columns: Date (A), Product (B), Amount (C).
- You want total sales per product, but you want the products listed across the top (as columns) and a single row of totals underneath.
- Your normal QUERY might be:
=QUERY(A1:C10, "select B, sum(C) group by B label sum(C) 'Total'")– this returns two columns: Product and Total, with each product on its own row. - To transpose that result, wrap it:
=TRANSPOSE(QUERY(A1:C10, "select B, sum(C) group by B label sum(C) 'Total'")). - The result will now have one row with product names in consecutive columns, and the row below it with the corresponding totals.
That’s it. The formula is dynamic—if the source data changes, both QUERY and TRANSPOSE recalculate automatically.
When Should You Use TRANSPOSE with QUERY?
There are several common scenarios where this combination shines:
- Pivot-like reports: When you want categories as columns instead of rows (e.g., months across the top).
- Preparing data for charts: Some charts (like certain line charts) expect series in rows or columns; transposing can help match the expected layout.
- Combining with other functions: You might transpose a query result before feeding it into functions like SORT or FILTER that work better with a particular orientation.
- Creating dashboards: Dashboards often need compact summary tables; transposing can turn a long vertical list into a wide, at-a-glance table.
However, don’t transpose just for the sake of it. If your data is already in the orientation you need, adding TRANSPOSE only adds complexity and can slow down your sheet if the dataset is large.
Common Problems and How to Fix Them
Here are the most frequent issues users run into when combining TRANSPOSE and QUERY:
- #VALUE! error: This often happens if the QUERY returns a single cell (like a scalar value). TRANSPOSE can’t flip a single value—it needs an array. If your QUERY returns one number, you don’t need TRANSPOSE.
- Array result truncated: If you see “Result was not automatically expanded, please insert more rows/columns,” it means the transposed result is larger than the empty space available. Make sure you have enough empty cells to the right (for horizontal expansion) or below (for vertical).
- Headers get flipped too: If your QUERY includes a header row (e.g., from the `label` clause), that header becomes a column after transposing. To avoid this, you might want to suppress headers in QUERY (using `label` with empty string) or handle them separately.
- Blank cells appear: If the original QUERY has empty cells, TRANSPOSE will place them as empty cells in the flipped result. This is normal, but you can filter them out with IFERROR or by adjusting the QUERY.
Another pitfall: when you transpose a QUERY that uses `order by`, the order is preserved, but the visual order changes—so a top-to-bottom order becomes left-to-right. Keep that in mind when designing your report.
TRANSPOSE(QUERY()) vs. Other Methods
There are alternative ways to achieve similar results, but each has trade-offs:
- Pivot Tables: A pivot table can reorient data without formulas, but it’s not dynamic in the same way (you must refresh it) and it doesn’t use QUERY’s SQL-like language.
- Copy and Paste Special > Transpose: This is static—if the source changes, you must repeat the process. It’s fine for one-time reports but not for live dashboards.
- Using QUERY with `pivot` clause: The QUERY function itself has a `pivot` clause that can turn values into columns. For example,
=QUERY(A1:C10, "select sum(C) pivot B")would give you one row with products as columns. This is often more efficient than transposing a group-by query, because it does the pivot in one step.
So, before you wrap TRANSPOSE, consider whether the QUERY’s built-in `pivot` clause can do the job. For instance, if you want months as columns, `pivot` is usually cleaner. However, `pivot` has limitations—it only works with one aggregate column, and it sorts the pivot values alphabetically. TRANSPOSE gives you more control over the order and layout.
Performance and Limitations
TRANSPOSE itself is a lightweight function, but when combined with QUERY on a large dataset, the calculation can become slow because QUERY is already resource-intensive. Google Sheets has a limit of about 50,000 cells per formula result, so a transposed query that would produce more than that will fail. Also, TRANSPOSE cannot be used on a range that includes entire columns (like A:A) because that would create an array of infinite size—you must specify a finite range.
If you’re working with thousands of rows, consider using a pivot table or a separate tab with a QUERY that outputs to a limited range, then transpose that smaller result.
Frequently Asked Questions
Can I transpose a QUERY result that has multiple columns?
Yes, absolutely. TRANSPOSE works on any array, including multi-column query results. For example, if your QUERY returns three columns (e.g., Product, Category, Total), TRANSPOSE will turn that into three rows, each with the data from the original column. The first row of the result will be the first column of the original, and so on.
Why does my TRANSPOSE(QUERY()) show only the first row?
This usually happens if you’re entering the formula in a cell that doesn’t have enough empty cells to the right or below. TRANSPOSE needs space to spill the result. If you see only the first row, check that the adjacent cells are empty. Also, if you’re using Excel, this is different—Excel requires you to press Ctrl+Shift+Enter for array formulas, but in Google Sheets, it’s automatic.
Can I use TRANSPOSE with QUERY that has a WHERE clause?
Yes, the WHERE clause works exactly the same. For example, =TRANSPOSE(QUERY(A1:C10, "select B, sum(C) where A > date '2023-01-01' group by B")) will filter the data first, then transpose the result. The order of operations is: QUERY processes the data, then TRANSPOSE flips it.
Does TRANSPOSE work with QUERY that returns dates or numbers?
Yes, it works with any data type. Dates will be transposed as dates, numbers as numbers, and text as text. Just be aware that if you have a date in the first column, after transposing it might become a row header, which could affect how you format it.
Is there a way to transpose without using the TRANSPOSE function?
Yes, you can use the QUERY function’s `pivot` clause for certain cases, or use copy-paste special > transpose for a one-time static flip. But if you need a live, formula-driven transpose, TRANSPOSE is the standard way. There’s also the `FLATTEN` function (in newer versions) but that’s for converting a range to a single column, not for transposing.
Final Thoughts on Combining TRANSPOSE and QUERY
Using TRANSPOSE with QUERY is a powerful way to reshape your data on the fly. The key is to understand that TRANSPOSE simply flips the array that QUERY returns, so you can design your QUERY to produce the data you want, then adjust the orientation as needed. Start with a simple example, test it on a small dataset, and then scale up. And remember, if you find yourself transposing a lot, check if the `pivot` clause in QUERY can do it more directly—it’s often the cleaner solution.
Related
- SUMIF Multiple Columns in Google Sheets: How-To
- Random Number Generator in Java: How to Use
- Data Entry Job: What It Really Involves Daily
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- MS Word Watermark: How to Add, Edit, and Remove OneTo add a watermark in Microsoft Word for Microsoft 365 on Windows, open Design > Watermark and choose…
- Add a Page Break in Excel: Steps, Layout, and Print TipsTo add a page break in Excel for Microsoft 365 on Windows, select the cell where the next…
- How to Change Double Spacing to Single Spacing in WordTo change double spacing to single spacing in Word, select the text (press Ctrl+A on Windows or Command+A…
- Excel Protect Sheet vs Protect Workbook: Key DifferencesProtect Sheet controls what people can change on an individual worksheet; Protect Workbook protects the workbook’s sheet structure,…
- Excel Find and Replace Regex: What Works and What Doesn’tNo: Excel’s Find and Replace dialog does not support regular expressions. In Microsoft 365, use the REGEXREPLACE worksheet…
- Delete a Scheduled Email in OutlookYes. In new Outlook or Outlook on the web, open the scheduled message in Drafts, choose Cancel send,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.