How do you do sumif with equation?
Categories:
Performing SUMIF with Equations in Excel

Learn how to use Excel's SUMIF function with dynamic criteria generated by equations, enabling powerful conditional summing.
The SUMIF
function in Excel is incredibly versatile for summing values based on a single criterion. While it's commonly used with direct values or cell references, its true power emerges when you combine it with equations. This allows for dynamic criteria that adapt to your data, enabling complex conditional sums without needing helper columns. This article will guide you through using equations within SUMIF
criteria, providing practical examples and explanations.
Understanding SUMIF Syntax
Before diving into equations, let's quickly review the basic syntax of the SUMIF
function:
SUMIF(range, criteria, [sum_range])
range
: The range of cells that you want to evaluate bycriteria
.criteria
: The condition in the form of a number, expression, cell reference, or text that defines which cells will be summed.sum_range
(optional): The actual cells to sum. If omitted, therange
is used.
>
, <
, >=
, <=
, or <>
with a value or a cell reference in criteria
, you must enclose the operator and the value/reference in double quotation marks. For example, ">100"
or ">"&A1
.Using Equations as Criteria
The key to using equations within SUMIF
is to construct a string that represents your dynamic criterion. This often involves concatenating an operator with the result of an equation or a cell reference. Excel evaluates this concatenated string as the condition.
Consider a scenario where you want to sum sales amounts that are greater than the average sales. You can't directly put ">AVERAGE(B2:B10)"
because AVERAGE(B2:B10)
would be treated as literal text. Instead, you concatenate the operator string ">"
with the result of the AVERAGE
function.
flowchart TD A["Start: Define Goal"] --> B["Identify 'range' to evaluate"]; B --> C["Identify 'sum_range' (if different)"]; C --> D["Determine Dynamic 'criteria'"]; D --> E{"Is criteria a simple value or text?"}; E -- Yes --> F["Use direct value/text or cell reference"]; E -- No --> G["Is criteria an operator + equation/reference?"]; G -- Yes --> H["Concatenate operator string with equation result: \" > \" & EQUATION()"]; G -- No --> I["Consider helper column or SUMPRODUCT"]; H --> J["Apply SUMIF(range, concatenated_criteria, sum_range)"]; F --> J; J --> K["End: Sum calculated"];
Decision flow for constructing SUMIF criteria with equations
Practical Examples
Let's look at some common scenarios where equations enhance SUMIF
.
Example 1: Summing Values Greater Than an Average
Suppose you have a list of product sales in column B (B2:B10) and you want to sum only those sales that are above the average of all sales.
=SUMIF(B2:B10, ">"&AVERAGE(B2:B10))
Summing sales greater than the average sales.
Here, AVERAGE(B2:B10)
calculates the average of the sales. The ">"&
concatenates the greater-than operator with this average, forming a dynamic criterion like ">150.75"
(if 150.75 was the average).
Example 2: Summing Based on a Date Calculation
Imagine you have transaction dates in column A (A2:A10) and amounts in column B (B2:B10). You want to sum amounts for transactions that occurred in the last 30 days from today's date.
=SUMIF(A2:A10, ">="&TODAY()-30, B2:B10)
Summing amounts for transactions within the last 30 days.
TODAY()-30
calculates the date 30 days ago. This is then concatenated with ">="
to create a criterion like ">=2023-10-26"
(assuming today is 2023-11-25). The sum_range
is specified as B2:B10
because we are evaluating dates but summing amounts.
Example 3: Summing Based on Text Length
If you have product names in column A (A2:A10) and their quantities in column B (B2:B10), and you want to sum quantities for product names that have more than 5 characters.
=SUMIF(A2:A10, ">"&5, B2:B10)
Summing quantities for product names longer than 5 characters.
This example is a bit tricky with SUMIF
directly on text length. SUMIF
evaluates the range
directly. To sum based on the length of text, you would typically need a helper column with LEN()
or use SUMPRODUCT
with LEN()
. The above SUMIF
example would only work if the cells in A2:A10
contained numbers that you wanted to compare to 5. For text length, SUMPRODUCT
is more appropriate:
=SUMPRODUCT(--(LEN(A2:A10)>5), B2:B10)
This highlights a limitation: SUMIF
's range
is evaluated directly, not by a derived property like LEN()
without a helper column. However, you can use an equation to define a numeric threshold for comparison against numeric values in the range
.
range
contains text, and your equation generates a number, SUMIF
might not behave as expected unless the text can be implicitly converted to a number for comparison (e.g., numbers stored as text).