This formula returns a count of rows where the value in column one is A or B and the value in column two is X, Y, or Z.

ISNUMBER + MATCH

Working from the inside out, each condition is applied with a separate ISNUMBER + MATCH expression. To generate a count of rows in column one where the value is A or B we use the following code: Notice the values “A” and “B” are supplied as an array constant and match_type is set to zero for an exact match. Note: the configuration for MATCH may appear “reversed” from what you might expect. This is necessary in order to preserve the structure of the source data in the results returned by MATCH, i.e. we get back seven results, one for each row in B5:B11. Since we give the MATCH function 7 values to look for, MATCH returns an array that contains 7 results like this: Each number in this array represents a match on “A” or “B” in Column B (1=“A”, 2=“B”). An #N/A error indicates a row where neither value was found. These results are delivered directly to the ISNUMBER function, which is used to convert the values from MATCH into simple TRUE and FALSE results: ISNUMBER returns a new array that looks like this: In this array, TRUE values represent rows where “A” or “B” were found in column B.  The next step is to test for “X”,“Y”,or “Z” in column C, and for this we use exactly the same approach: With the above configuration, the MATCH function returns the following array: As before, the ISNUMBER function converts these results to TRUE and FALSE values and returns an array like this: We now have everything we need to perform the count, and for this we use the SUMPRODUCT function.

SUMPRODUCT function

The final step in the formula is to tally up the rows that meet the criteria outlined above. In the example shown, the formula in F10 is: After the two MATCH and ISNUMBER expressions are evaluated, the formula simplifies to the following: Next, the two arrays are multiplied together inside SUMPRODUCT, which automatically converts TRUE FALSE values to 1s and 0s as a result of the math operation: Once the two arrays are multiplied together, we have a single array like this: In this array, a 1 signifies a row that meets all criteria and a 0 indicates a row that does not. With just a single array to process, SUMPRODUCT sums the array and returns a final result of 5.

With cell references

The example above uses hardcoded array constants, but you can also use cell references: This approach can be “scaled up” to handle more criteria. You can see an example in this formula challenge. Note: The SUMPRODUCT function is used below for compatibility with Legacy Excel. In the current version of Excel, you can use the SUM function instead. For more on this topic, see: Why SUMPRODUCT?

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.