(Excel examples for Beginners)
In this end-to-end excel example, you will learn – How to Count total matches in two ranges in Excel.
How to Count total matches in two ranges in Excel
Generic formula
=SUMPRODUCT(COUNTIF(range1,range2))
Explanation
If you want to compare two ranges, and count total matches between the two ranges, you can use a formula that combines the COUNTIF and SUMPRODUCT functions.
Context
Suppose you have a “master” list of some kind, and also have another list that contains some of the same items. You want a formula that compares the values in the 2nd list to see how many of them appear in the first list. You don’t care about the order that the items — you just want to know how many items in list 2 appear in list 1.
Solution
The formula we are using in cell G7 is:
=SUMPRODUCT(COUNTIF(B5:B11,D5:D11))
Note that this formula does not care about the location or order of the items in each range.
Explanation
The COUNTIF function will count things in a range that meet your criteria. Normally, you would give COUNT if a range like A1:A10 and a simple criteria like “>10”. COUNTIF would then return the count of cells in A1:A10 that are greater than 10.
In this case however, we are giving COUNTIF a range for criteria. We aren’t using any logical operators, which means COUNTIF will check for equivalency (i.e. it behaves as if we used the equals (=) operator).
Because we give COUNTIF a range (also called an “array”) that contains 7 items, COUNTIF will return an array of 7 items as a result. Each item in the result array represents a count. In the example, this array that COUNTIF returns looks like this:
{1;1;0;1;1;0;0}
Now we simply need to add up the items in this array, which is a perfect job for SUMPRODUCT. The SUMPRODUCT function is a versatile function that handles arrays natively without any special array syntax.
If you give SUMPRODUCT two or more arrays, it will multiple the arrays together, sum up the results, and return that number. In this case, we give SUMPRODUCT just one array, so it simply sums up the items in the array and returns 4 as the result.
Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.
Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners
Latest end-to-end Learn by Coding Projects (Jupyter Notebooks) in Python and R:
All Notebooks in One Bundle: Data Science Recipes and Examples in Python & R.
End-to-End Python Machine Learning Recipes & Examples.
End-to-End R Machine Learning Recipes & Examples.
Applied Statistics with R for Beginners and Business Professionals
Data Science and Machine Learning Projects in Python: Tabular Data Analytics
Data Science and Machine Learning Projects in R: Tabular Data Analytics
Python Machine Learning & Data Science Recipes: Learn by Coding
R Machine Learning & Data Science Recipes: Learn by Coding
Comparing Different Machine Learning Algorithms in Python for Classification (FREE)
There are 2000+ End-to-End Python & R Notebooks are available to build Professional Portfolio as a Data Scientist and/or Machine Learning Specialist. All Notebooks are only $29.95. We would like to request you to have a look at the website for FREE the end-to-end notebooks, and then decide whether you would like to purchase or not.
R tutorials for Business Analyst – Bar Chart and Histogram in R
Excel formula for Beginners – How to Count cells equal to something