Google Sheets – Count Blank Cells Based on Related Cell Information

google sheets

I'm trying to use information from a table to display a count of blank cells based on the type of data in the table. See my example below – I want to count how many of each fruit I'm missing, regardless of their color, and ignoring the apples I do have.

Table:

End result:

Best Answer

The following formula will almost retrieve the table you want.

Formula

 QUERY(data, query, headers)

=QUERY(
   DATA!A1:C7,                                         // data
   "SELECT A, COUNT(B) WHERE C IS NULL GROUP BY A      // query
      LABEL COUNT(B) 'Amount of Empty Types'"             
 )

Explained

Column A is selected to be shown. It is not possible, with the QUERY formula, to perform on the same column a count and select operation. Therefore I performed the count on column B. The where clause on column C is set to contain nothing. All results are to be grouped by column A. At the end of the query, the header/label is changed (otherwise it would show "count Color".

Result

enter image description here

Example

I've created an example file for you: Counting blank cells based on information in related cell