Clark Uy
Clark Uy

Reputation: 3

Google Sheets Query: Multiple Values in a Single Cell Reference, is it possible?

Good morning!

I want to ask if it is possible that the cell reference for "houses" on "worksheet!C3" return values for A&B only or A&C only or B&C only while only using one cell ("worksheet!C3") as cell reference, or is there a better approach on trying to return the values?

formula I'm using:

sum(query(Encoding!$A$4:$K$9,"Select D where (A contains '"&C$2&"') and (B contains '"&C$3&"') and (C = date '"&text($B$4,"yyyy-mm-dd")&"')"))

Sample data is attached,

https://docs.google.com/spreadsheets/d/1sY6YQRQ6Im-zTdzf0u31rphnQR0eL_YzDahpgMQ7E1Y/edit#gid=37782805

Upvotes: 0

Views: 1676

Answers (1)

Mike Steelson
Mike Steelson

Reputation: 15328

Try, as far as I understood the subject correctly

=sum(query(Encoding!$A$4:$K$9,"Select D where (A contains '"&C$2&"') and (B contains '"&C$3&"' or B contains '"&C$4&"') and (C = date '"&text($B$4,"yyyy-mm-dd")&"')"))

you can also put one formula in A5 as follows

=sort(query(arrayformula(split(flatten(Encoding!A4:A9&"~"&Encoding!B4:B9&"~"&Encoding!C4:C9&"~"&Encoding!D3:K3&"~"&Encoding!D4:K9),"~",true)),
"select Col4,sum(Col5) where Col3="&B4&" and (Col2 contains '"&C$3&"' or Col2 contains '"&C$4&"') and Col1="&C2&"  group by Col4 label sum(Col5) ''"),1,0)

enter image description here

Upvotes: 0

Related Questions