# How can I query columns instead of rows in a =QUERY?

With this formula, I can get a list of the columns with the highest total

``````=QUERY(A2:D5, "Select A,D Order by D Desc Limit 4")
``````

But I can't figure out how to do the opposite, find the columns with the highest total, and return a list of that. (so it should list betty|12, aaron|6)

• Please edit this question for clarity. It doesn't make sense as it's written. You already have those totals. Why do you want the totals row? Sep 14 at 0:19
• I wanted the totals row to be sorted, to see which columns have the highest totals Sep 14 at 17:45

## 1 Answer

One option is to use TRANSPOSE. This function change columns to rows.

NOTE: When feeding QUERY with an array of values, like the result of transpose, instead of using the column letters as field names, use Col1, Col2, according to the column position of the feed array of values.

``````=QUERY(TRANSPOSE(A1:C5),"SELECT Col1,Col5 Order By Col5 Desc")
``````

total
betty 12
aaron 6
• Ah that's the key! I actually did see transpose, but when I tried it by selecting A (I assumed they would get remapped to the column letters), it said A didn't exist. ColX is the secret! Sep 14 at 17:44