Excel formula for Beginners – How to SUMPRODUCT with IF in Excel

 

(Excel examples for Beginners)

In this end-to-end excel example, you will learn – Excel formula for Beginners – How to SUMPRODUCT with IF in Excel.

 

Excel formula for Beginners – How to SUMPRODUCT with IF in Excel

Generic formula

=SUMPRODUCT(expression,range)

Explanation

To filter results of SUMPRODUCT with specific criteria, you can apply simple logical expressions directly to arrays in the function, instead of using the IF function. In the example shown, the formulas in H5:H7 are:

=SUMPRODUCT(--(color="red"),quantity,price)
=SUMPRODUCT(--(state="tx"),--(color="red"),quantity,price) 
=SUMPRODUCT(--(state="co"),--(color="blue"),quantity,price)

where the following named ranges are defined:

state=B5:B14
color=C5:C14
quantity=D5:D14
price=E5:E14

If you’d rather avoid named ranges, use the ranges above entered as absolute references. The logical expressions in H6 and H7 can be combined, as explained below.

How this formula works

This example illustrates one of the key strengths of the SUMPRODUCT function – the ability to filter data with basic logical expressions instead of the IF function. Inside SUMPRODUCT, the first array is a logical expression to filter on the color “red”:

--(color="red")

This results in an array or TRUE FALSE values, which are coerced into ones and zeros with the double negative (–) operation. The result is this array:

{1;0;1;0;0;0;1;0;0;0}

Notice the array contains 10 values, one for each row. A one indicates a row where the color is “red” and a zero indicates a row with any other color.

Next, we have two more arrays: one for quantity and one for price. Together with this results from the first array, we have:

=SUMPRODUCT({1;0;1;0;0;0;1;0;0;0},quantity,price)

Expanding the arrays, we have:

=SUMPRODUCT({1;0;1;0;0;0;1;0;0;0},{10;6;14;9;11;10;8;9;11;10},{15;18;15;16;18;18;15;16;18;16})

SUMPRODUCT’s core behavior is to multiply, then sum arrays. Since we are working with three arrays, we can visualize the operation as shown in the table below, where the result column is the result of multiplying array1 * array2 * array3:

array1 array2 array3 result
1 10 15 150
0 6 18 0
1 14 15 210
0 9 16 0
0 11 18 0
0 10 18 0
1 8 15 120
0 9 16 0
0 11 18 0
0 10 16 0

Notice array1 works as a filter – zero values here “zero out” values in rows where the color is not “red”. Putting the results back into SUMPRODUCT, we have:

=SUMPRODUCT({150;0;210;0;0;0;120;0;0;0})

Which returns a final result of 480.

Adding additional criteria

You can extend criteria by adding another logical expression. For example, to find total sales where the color is “Red” and the state is “TX”,  H6 contains:

=SUMPRODUCT(--(state="tx"),--(color="red"),quantity,price)

Note: SUMPRODUCT is not case-sensitive.

Simplifying with a single array

Excel pros will often simplify the syntax inside SUMPRODUCT a bit by multiplying arrays directly inside array1 like this:

=SUMPRODUCT((state="tx")*(color="red")*quantity*price)

This works because the math operation (multiplication) automatically coerces the TRUE and FALSE values from the first two expressions into ones and zeros.

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!

 

Learn Java by Example: Java Program to Concatenate Two Arrays

R tutorials for Business Analyst – R IF, ELSE, ELSE IF Statement

Python Exercise – Sum of three given integers if two values are equal sum will be zero