Excel formula for Beginners – How to Sum matching columns in Excel

(Excel examples for Beginners)

In this end-to-end excel example, you will learn – Excel formula for Beginners – How to Sum matching columns in Excel.

 

Excel formula for Beginners – How to Sum matching columns in Excel

Generic formula

=SUMPRODUCT(data*(headers=A1))

Explanation

To sum values in columns by matching matching column headers, you can use a formula based on the SUMPRODUCT function. In the example shown, the formula in J5 is:

=SUMPRODUCT(data*(LEFT(headers)=J4))

where “data” is the named range B5:G14, and “headers” is the named range B4:G4.

The formula sums columns where headers begin with “a” and returns 201.

How this formula works

At the core, this formula relies on the SUMPRODUCT function to sum values in matching columns in the named range “data” C5:G14. If all data were provided to SUMPRODUCT in a single range, the result would be the sum of all values in the range:

=SUMPRODUCT(data) // all data, returns 387

To apply a filter by matching column headers – columns with headers that begin with “A” – we use the LEFT function like this:

LEFT(headers)=J4) // must begin with "a"

This expression returns TRUE if a column header begins with “a”, and FALSE if not. The result is an array:

{TRUE,TRUE,FALSE,FALSE,TRUE,FALSE}

You can see that values 1,2, and 5 correspond to columns that begin with “a”.

Inside SUMPRODUCT, this array is multiplied by “data”. Due to broadcasting, the result is a two-dimensional array like this:

{8,10,0,0,7,0;9,10,0,0,10,0;8,6,0,0,6,0;7,6,0,0,6,0;8,6,0,0,6,0;10,11,0,0,7,0;7,8,0,0,8,0;2,3,0,0,3,0;3,4,0,0,4,0;7,7,0,0,4,0}

If we visualize this array in a table, it’s easy to see that only values in columns that begin with “a” have survived the operation, all other columns are zero. In other words, the filter keeps values of interest and “cancels out” the rest:

A001 A002 B001 B002 A003 B003
8 10 0 0 7 0
9 10 0 0 10 0
8 6 0 0 6 0
7 6 0 0 6 0
8 6 0 0 6 0
10 11 0 0 7 0
7 8 0 0 8 0
2 3 0 0 3 0
3 4 0 0 4 0
7 7 0 0 4 0

With only a single array to process, SUMPRODUCT returns the sum of all values, 201.

Sum by exact match

The example above shows how to sum columns that begin with one or more specific characters. To sum column based on an exact match, you can use a simpler formula like this:

=SUMPRODUCT(data*(headers=J4))

Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

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

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!

 

Beginner’s Project on Regression in Python

Excel formula for Beginners – How to Count cells that begin with something in Excel

Data Wrangling in Python – How to Rename Column Headers In pandas