Countifs in Google Sheets with various 'differ

2019-08-13 02:07发布

问题:

I'm trying to count all values different than some specific criteria on the same row in a Google sheet that is feed via a google form but the final count shows "1".

The row I'm counting from corresponds to a multiple choice question that has an 'other' option so the user can enter other values and I'm trying to count the number of 'other' values in the row.

I tried normal count and couldif but when you use a <> it ends up counting to infinite if you want to check a B2:B range (B1 Is the heading), so I used a structure of this:

=COUNTIFS(query('FORMS RESPONSES'!B2:B,"<>TYPE A"), 
query('FORMS RESPONSES'!B2:B,"<>TYPE B"),
query('FORMS RESPONSES'!B2:B,"<>TYPE C"),
query('FORMS RESPONSES'!B2:B,"<>TYPE D"),
query('FORMS RESPONSES'!B2:B,"<>TYPE E"),
)

Assuming the feed has 1 response for A, B, C, and none for D, E and 2 other entries with random values, the answer should be = 2, yet it gives me only = 1

I have this:

=COUNTIFS(
query(datos!B2:B,"<>PC Tipo 1 (HP)")
,query(datos!B2:B,"<>PC Tipo 2 (Lenovo)")
,query(datos!B2:B,"<>PC Tipo 3 (Dell)")
,query(datos!B2:B,"<>Laptop Tipo 1 (Lenovo)")
,query(datos!B2:B,"<>Laptop Tipo 2 (Thinkpad)")
,query(datos!B2:B,"<>Tel Cel.")
)

VG:

An sample data entry for B2:B would be:

  • PC Tipo 1 (HP)
  • PC Tipo 2 (Lenovo)
  • PC Tipo 3 (Dell)
  • Laptop Tipo 1 (Lenovo)
  • server HP
  • Projector

So there are 6 total entries with 2 being the 'other' kind that I'm trying to count (server HP and Projector). Yet the result gives me =1

回答1:

you are getting 1 as one error counted. do it like this:

=COUNTA(QUERY(datos!B2:B, "where not B contains 'PC Tipo 1 (HP)' 
                             and not B contains 'PC Tipo 2 (Lenovo)'
                             and not B contains 'PC Tipo 3 (Dell)'
                             and not B contains 'Laptop Tipo 1 (Lenovo)'
                             and not B contains 'Laptop Tipo 2 (Thinkpad)'
                             and not B contains 'Tel Cel.'", 0))



回答2:

or you can do it like this:

=ARRAYFORMULA(COUNTA(datos!B2:B)-
 SUM(COUNTIF(datos!B2:B, {"PC Tipo 1 (HP)",
                          "PC Tipo 2 (Lenovo)",
                          "PC Tipo 3 (Dell)",
                          "Laptop Tipo 1 (Lenovo)",
                          "Laptop Tipo 2 (Thinkpad)",
                          "Tel Cel."})))