While the COUNTIFS function is the standard go-to for counting data based on criteria in Excel, it has its limitations—particularly when dealing with arrays or transforming data within the formula itself (such as extracting a month from a date). This is where the SUMPRODUCT function shines.
At Thủ Thuật, we believe in mastering versatile tools. SUMPRODUCT is not just for multiplication; it is a powerhouse for array processing that can handle complex counting logic where other functions fail. This guide will walk you through how to utilize SUMPRODUCT to count with multiple conditions, offering you a more flexible way to analyze your data.
Understanding the Logic of SUMPRODUCT
To master this technique, it is essential to understand how SUMPRODUCT processes data. Unlike standard counting functions, SUMPRODUCT handles arrays naturally.
The basic syntax is:
=SUMPRODUCT(array1, [array2], [array3], …)How It Counts
The “secret” to using this function for counting lies in Boolean logic. When you set a condition in Excel (e.g., A1="Apple"), the result is either TRUE or FALSE.
- TRUE is equivalent to 1.
- FALSE is equivalent to 0.
By multiplying these conditions together, SUMPRODUCT checks if all criteria are met for a specific row. If a row meets all conditions (1 * 1 * 1), the result is 1. If it fails even one condition (1 * 0 * 1), the result is 0. Finally, the function sums up these 1s to give you the total count.
Practical Application: Counting with Multiple Criteria
Let’s dive into a practical scenario to see this function in action. We will use a sales dataset containing dates, shift numbers, product names, and quantities.
The Dataset
Below is an animation showing how data is typically selected in these operations, followed by our static dataset for this tutorial.
Animation demonstrating the selection of data ranges in Excel for SUMPRODUCT formulas
Our specific dataset includes columns for Date (Ngày), Shift (Ca), Product Name (Tên hàng), and Quantity (Số lượng).
Spreadsheet table showing columns for Date, Shift, Product Name, and Quantity with sample sales data
Example 1: Counting Specific Products in a Specific Month
The Challenge: We need to count how many times “Cam” (Orange) was sold specifically in June.
The Analysis:
- Condition 1 (Product): Look at column C (“Tên hàng”) for the text “Cam”.
- Condition 2 (Time): Look at column A (“Ngày”). However, the data is in full date format (dd/mm/yyyy). We need to extract just the month using the
MONTH()function.
Note: This is a scenario where COUNTIFS often struggles because it cannot process MONTH(Range) directly inside its arguments without a helper column.
The Formula:
=SUMPRODUCT((C2:C18="Cam")*(MONTH(A2:A18)=6)*1)Breakdown:
(C2:C18="Cam"): Creates an array of TRUE/FALSE for the product name.(MONTH(A2:A18)=6): Extracts the month from column A and checks if it equals 6 (June).*: The multiplication operator acts as an “AND” logic gate.*1: Ensures the final Boolean result is coerced into a number (though the multiplication between two arrays usually handles this, adding*1is a safe habit to ensure numeric conversion).
Pro Tip: Always lock your reference ranges (using F4 to add $ signs, e.g., $C$2:$C$18) if you plan to drag the formula to other cells.
Excel screenshot showing the SUMPRODUCT formula result for counting Oranges sold in June
Example 2: Advanced Counting with Three Conditions
The Challenge: We need to count the number of times “Táo” (Apple) was sold in Shift 1 during June.
The Analysis:
We are now layering three distinct criteria:
- Shift: Column B must equal
1. - Month: Column A must be June (
6). - Product: Column C must be “Táo”.
The Formula:
=SUMPRODUCT(($B$2:$B$18=1)*(MONTH($A$2:$A$18)=6)*($C$2:$C$18="Táo")*1)As you can see, adding criteria does not complicate the logic; it simply extends the multiplication chain. Each condition is enclosed in parentheses and multiplied by the next.
Excel screenshot showing the result for counting Apples sold in Shift 1 during June
Why Use SUMPRODUCT Instead of COUNTIFS?
While COUNTIFS is faster for simple matches, SUMPRODUCT offers superior flexibility:
- Data Transformation: You can modify the data range (like extracting a Year or Month) directly within the formula.
- Complex Logic: It handles “OR” logic (using
+instead of*) more intuitively thanCOUNTIFSin a single cell. - Array Handling: It is designed for matrix calculations, making it a favorite for advanced modeling.
Conclusion
The SUMPRODUCT function is an incredibly powerful tool for anyone looking to go beyond basic Excel counting. By understanding how to multiply logical conditions, you can extract precise insights from your data without the need for messy helper columns.
Whether you are tracking inventory, analyzing sales shifts, or managing project timelines, mastering this function will significantly enhance your spreadsheet efficiency. We encourage you to experiment with these formulas on your own datasets to fully grasp their potential.
For more advanced Excel techniques and technology tips, keep following Thủ Thuật.










Discussion about this post