0
votes

I am trying to query data from a sheet matching two conditions. However, when there is more than 1 row in the data matching my condition the query only returns the first result. How do I make sure it returns ALL rows matching the conditions?

I tried changing the single and double quotes, capital letters, changing the format of the data but nothing worked.

The query:

query(Raw!A1:J29041, "select B,C,D,E, sum(F) where B='"&sheet1!A2&"' and E='good source' and not C='2016' GROUP BY B,C,D,E")

Example of data:

Client     Year    Month    Source         Count
Client a    2019    July    other source    1
Client a    2019    July    good source     2
Client a    2019    July    bad source      22
Client a    2019    July    good source     63
Client a    2019    July    another source  1
Client a    2019    July    another source  8

Desired output for this data:

Client      Year    Month   Source          sum
Client a    2019    July    other source    65
1

1 Answers

1
votes

numbers shouldn't be enclosed with single quotes

try:

=QUERY(Raw!A1:J29041, 
 "select B,C,D,E,sum(F) 
  where B="&sheet1!A2&" 
    and E='good source' 
    and not C='2016' 
  group by B,C,D,E", 1)

or:

=QUERY(Raw!A1:J29041, 
 "select B,C,D,E,sum(F) 
  where B="&sheet1!A2&" 
    and E='good source' 
    and not C=2016 
  group by B,C,D,E", 1)