Google sheets query select when certain values

I am trying to make the formula bellow work as follows: Get the values on A when B matches the values on E (for the sample it would be 1,2,4,5,7,8).

=QUERY({IMPORTRANGE("1Cg9gx2IhBUYwElNXprNJnihixbMLJcK1DKzIClQDNwc";"DATA!A2:C")};"select Col1 Where Col3 >= date '"&TEXT(TODAY;"yyyy-mm-dd")&"'and Col3 <= date '"&TEXT(TODAY;"yyyy-mm-dd")&"'and Col2="&(E1:E2)&"";0)

sample data:

A   B   C           E
1   X   27/02/2019  X
2   Y   27/02/2019  Y
3   Z   27/02/2019  
4   X   27/02/2019  
5   Y   27/02/2019  
6   Z   27/02/2019  
7   X   27/02/2019  
8   Y   27/02/2019  

How can I accomplish that?

Upvotes: 1

Views: 406

Answers (2)

player0
player0

Reputation: 1

  • QUERY can't handle array/range inside quoted part
  • TODAY needs to be with () like TODAY()
  • today it's 28. february (at least where my sheet lives)

=QUERY(IMPORTRANGE("1Cg9gx2IhBUYwElNXprNJnihixbMLJcK1DKzIClQDNwc"; "DATA!A2:C");
 "select Col1 
  where Col3 >= date '"&TEXT(TODAY(); "yyyy-MM-dd")&"'
    and Col3 <= date '"&TEXT(TODAY(); "yyyy-MM-dd")&"'
    and (Col2 = '"&E1&"'
     or  Col2 = '"&E2&"')"; 0)

or try like this if you have array/range of values:

=QUERY(FILTER(IMPORTRANGE("1Cg9gx2IhBUYwElNXprNJnihixbMLJcK1DKzIClQDNwc"; "DATA!A2:C100"); 
 COUNTIF(E1:E100; "="&
 IMPORTRANGE("1Cg9gx2IhBUYwElNXprNJnihixbMLJcK1DKzIClQDNwc"; "DATA!B2:B100"))); 
 "select Col1 
   where Col3 >= date '"&TEXT(TODAY(); "yyyy-MM-dd")&"' 
     and Col3 <= date '"&TEXT(TODAY(); "yyyy-MM-dd")&"'"; 0)

Upvotes: 0

pnuts
pnuts

Reputation: 59475

Try for the "where" clause:

where  Col2='"&E3&"' or Col2 ='"&E2&"'

SO54912607 example

Upvotes: 1

Related Questions