Search code examples
google-sheetsgoogle-sheets-formulagoogle-query-language

Selecting few columns in Google Sheet's QUERY function


I am trying to select few columns in Google Sheet's QUERY function but get errors when I combine with other formula in the function.

Here is my formula. What I am trying to do? my goal is combine data (column) from different sheets that will ultimately feed into a pivot table

=QUERY({TeamData!C:C,TeamBonusData!F:F;IndividualData!M:O,IndividualBonusData!P:R},) - this does not work

=QUERY({TeamData!C:C,TeamData!F:F},) - this works.


Solution

  • Follow the advice Tedinoz gave and ensure that those references have a matching number of rows and columns. It may help if you visually group ranges so that they stack side-by-side or on top of each other, like this:

    =lambda( 
      teams, teamsBonus, individuals, individualsBonus, 
      lambda( 
        numTeams, numIndividuals, 
        {
          array_constrain(teams, numTeams, 2), array_constrain(teamsBonus, numTeams, 2); 
          array_constrain(individuals, numIndividuals, 2), array_constrain(individualsBonus, numIndividuals, 2) 
        }
      )(
        min(rows(teams), rows(teamsBonus)), 
        min(rows(individuals), rows(individualsBonus)) 
      ) 
    )( 
      TeamData!C2:D, TeamBonusData!F2:G, IndividualData!M2:O, IndividualBonusData!P2:R 
    )