Search code examples
sortinggoogle-sheetstransposegoogle-sheets-querygoogle-query-language

Google Sheets Query list by row and sort


I am trying to set up a query in a Google sheet that shows a column of data based on the header and then sorts the numerical values in the column and keeps the referencing row. https://docs.google.com/spreadsheets/d/14kQxqck_NbJ195IF3ALOgFIR23K5nKqXRuk47nvUDoo/edit?usp=sharing

I have read through the wiki help on Google Sheets for query and I'm lost of what to do to get the results I want.

=query(TeamNeeds!B1:O39,"where C='"&C1&"'",-1) is what I have currently and I know it isn't close to what I need.

I would like to use the dropdown in C1 and have it show the associated column on the next sheet over and then sort the data with updating referencing titles (FLYING, GROUND, ROCK, etc.)

+------------+
|   Pidgey   |
+--------+---+
| FIRE   | 3 |
+--------+---+
| GROUND | 2 |
+--------+---+
| ICE    | 0 |
+--------+---+

Solution

  • =QUERY({TeamNeeds!A1:A, TRANSPOSE(QUERY(TRANSPOSE(TeamNeeds!B1:AC), 
     "where Col1 = '"&C1&"'", 0))}, 
     "order by Col2 Desc", 1)
    

    0


    =QUERY(QUERY({TeamNeeds!A1:A, TRANSPOSE(QUERY(TRANSPOSE(TeamNeeds!B1:AC), 
     "where Col1 = '"&C1&"'", 0))}, 
     "order by Col2 Desc", 1), 
     "offset 1", 0)
    

    0