Where data is an Excel Table in the range B5:D15. The result is two, since there are 2 males not in Group A or B. Note: You can also solve this problem with the COUNTIFS function, as explained below. The SUMPRODUCT formula is more advanced, but it scales better when there many exclusions.

### COUNTIFS function

The COUNTIFS function returns the count of cells that meet one or more criteria, and supports logical operators (>,<,<>,=) and wildcards (*,?) for partial matching. Conditions are supplied to COUNTIFS in the form of range/criteria pairs — each pair contains one range and the associated criteria for that range: In this case, the first condition is that Gender is Male: The result is 6, since there are six Males in the table. Next, we need to exclude group “A”: This formula returns 5. Notice we use the not equal to operator (<>) enclosed in double quotes. Finally, we need to exclude group B with another range/criteria pair: Notice the syntax to exclude group B is the same and both conditions use the same range. This formula returns 2. The COUNTIFS function joins all criteria with AND logic, so it works well to exclude A and B in this case. As more exclusions are added however, the syntax gets more cumbersome, because each new exclusion requires another range/criteria pair. The SUMPRODUCT option below scales more easily.

### SUMPRODUCT function

Another way to solve this problem is with the SUMPRODUCT function and Boolean logic. To start off, we can count males like this: Working from the inside out, this expression tests all values in the Gender column for “Male”: Since there are 11 cells in the column, the result is an array with 11 TRUE and FALSE values: Each TRUE represents a “Male” in the Gender column. SUMPRODUCT will ignore TRUE and FALSE values by default, so we need to convert these TRUE and FALSE values to their numeric equivalents, 1 and 0. A simple way to do this is with a double negative (–): The result from this snippet is an array like this: Notice the TRUE values are now 1s. This array is delivered to SUMPRODUCT, which returns 6: Next, we need to exclude groups “A” and “B”. A good way to do this is with the MATCH function together with the ISNA function like this: Notice the configuration of MATCH is “reversed”. The lookup_value is given as data[Group], and the lookup_array is given as the array constant {“A”,“B”}. We do it this way to keep the rows in the output array consistent with the table. The result from MATCH is an array like this: This array has 11 rows, like the data table. The numbers indicated rows where group “A” or “B” were found. The #N/A errors indicate rows where group “A” or “B” were not found. To convert this array into something we can use, we use the ISNA function: The result from ISNA is an array of TRUE and FALSE values like this: ISNA returns TRUE only for the #N/A errors, so the TRUE values in this array indicate rows where the group was not “A” or “B”. If we wanted to use this expression in SUMPRODUCT by itself, we would use a formula like this: The double negative (–) again converts TRUE and FALSE values, and the result looks like this: The result is 3, since there are 3 records not in group A or B.

### Putting it all together

The next step is to put both tests above together inside SUMPRODUCT like this: Notice we use multiplication (*) to join the two expressions. We do this because multiplication corresponds to AND logic in Boolean algebra. Also notice that we no longer need the double negative (–). This is because the math operation of multiplication automatically converts the TRUE and FALSE values to 1s and 0s. The formula evaluates like this: The final result is 2, since there are 2 males not in Group A or B. Note: In Excel 365 and Excel 2021 you can use the SUM function instead of SUMPRODUCT if you prefer. This article provides more detail.

### Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.