How could we use a formula in query Google sheet

97 views Asked by At

I am unable to figure out how could we use formula within query results. I did not find any solution yet.

Like:

=query(sheet1!A1:Z,"Select A,B,Vlookup(D,sheet1!A1:A,1,false)");
2

There are 2 answers

0
ziganotschka On
  1. If your range is A1:Z, the column where you can insert the formula without error must be bigger than Z
  2. Sheet formulas do not expect (nor allow) semicola at the end
  3. If D is a string, it should be nested in double quotes
  4. To combine your formulas, you need to combine the quotes correctly, e.g.:
=query(Sheet1!A1:Z, CONCATENATE("select A,B,",Vlookup("D",Sheet1!A1:A,1,false)))
0
player0 On

you can't. you need to do:

=ARRAYFORMULA({sheet1!A:B, IFNA(VLOOKUP(D:D, sheet1!A:A, 1, 0))})

and then you can play with query:

=ARRAYFORMULA(QUERY({sheet1!A:B, IFNA(VLOOKUP(D:D, sheet1!A:A, 1, 0))}, "select Col1,Col2,Col3", 0)