Skip to content
Free Excel Tutorials
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Data Analysis

  • Calculate Conditional Percentile ‘IF’ in table in Excel
  • Use Data Form to input, edit and delete records in Excel
  • Subtotal function in Excel
  • How To Create Pareto Chart in Excel
  • How to Create One and Two Variable Data Tables in Excel

References

  • How to get relative row numbers in a range in Excel
  • How to calculate two-way lookup VLOOKUP in Excel Table
  • MATCH function: Description, Usage, Syntax, Examples and Explanation
  • How to use Excel ROW Function
  • How to get first row number in range in Excel

Data Validations

  • Data validation must not exist in list
  • Excel Data validation number multiple 100
  • Excel Data validation require unique number
  • Excel Data validation no punctuation
  • Excel Data validation whole percentage only

SUMPRODUCT with IF in Excel

by

This tutorial shows how to SUMPRODUCT with IF in Excel using the example below;

Formula

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

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 formula in H5 is:

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

Named ranges

The example uses several named ranges, for convenience only:

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.

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.

Worked Example:   Count birthdays by month in Excel

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:

Worked Example:   Count multiple criteria with NOT logic in Excel
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.

Worked Example:   Weighted average in Excel

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.

Post navigation

Previous Post:

44 Practical Excel IF function Examples

Next Post:

Large with criteria in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others

Logical Functions

  • IFS function: Description, Usage, Syntax, Examples and Explanation
  • Not Equal To ‘<>‘ operator in Excel
  • OR function: Description, Usage, Syntax, Examples and Explanation
  • IF with boolean logic in Excel
  • XOR function: Description, Usage, Syntax, Examples and Explanation

Date Time

  • TIME function: Description, Usage, Syntax, Examples and Explanation
  • Display Date is workday in Excel
  • Convert text to date in Excel
  • Calculate time difference in hours as decimal value in Excel
  • Roll back weekday to Friday base on a particular date in Excel

Grouping

  • Group times into unequal buckets in Excel
  • If cell contains one of many things in Excel
  • Group arbitrary text values in Excel
  • How to randomly assign people to groups in Excel
  • Calculate conditional mode with criteria in Excel

General

  • Find, Select, Replace and Go To Special in Excel
  • How to get Excel workbook path only
  • Excel Autofill Cell Ranges, Copy, Paste
  • Select, Insert, Rename, Move, Delete Worksheets in Excel
  • How to create dynamic named range with INDEX in Excel
© 2023 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning