5

When I use the =QUERY function in Google Sheets, it returns the value in the cell beneath where I typed the function. I want the returned value to appear in the cell I typed the function. Currently, I have

=QUERY(Data!$L:$N,"select avg(N) where L = '"&CONCATENATE(B$1,$A2)&"'")

in cell B2, and it is returning the value in B3.

How can I return the value into B2 instead of B3?

tehhowch
  • 9,645
  • 4
  • 24
  • 42
John Doe
  • 121
  • 1
  • 3
  • 9

2 Answers2

13

It is returning you an array containing the name of the calculating SQL function first and then the result. To subvert this behavior, you could do the following.

=INDEX(QUERY(Data!$L:$N,"select avg(N) where L = '"&CONCATENATE(B$1,$A2)&"'"),2)
Jeremy Kahan
  • 3,796
  • 1
  • 10
  • 23
  • 2
    you can also use something like this `=QUERY(Data!$L:$N,"select avg(N) where L = '"&CONCATENATE(B$1,$A2)&"' limit 1")` if you just want one result only instead of an array – wildmonkey Sep 19 '20 at 12:10
6

The query language itself allows for this by permitting application of a blank label:

=QUERY(Data!$L:$N,"select avg(N) where L='"&B$1&$A2&"' label avg(N)''")
pnuts
  • 58,317
  • 11
  • 87
  • 139