Using COUNTIF and SUMIF for Conditional Aggregation in Spreadsheets#
š Analyze Data š§® Calculations & Aggregation Lesson 021
ā Previous Ā· Next ā¶ Ā· ā Section Ā· ā Hub
Important
⨠AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
Aggregating with a condition#
Plain SUM and COUNT aggregate everything; analysis usually needs to
aggregate only the rows meeting a condition ā sales in one region, orders above a
threshold, customers of one type. COUNTIF and SUMIF are the spreadsheetās
conditional-aggregation functions, and they are among the most-used analytical
tools, the spreadsheet counterparts of SQLās COUNT/SUM with WHERE.
COUNTIF and SUMIF#
COUNTIF(range, condition)ā counts the cells in a range that meet a condition:=COUNTIF(region, "North") how many northern orders =COUNTIF(amount, ">100") how many orders over 100
SUMIF(range, condition, sum_range)ā sums the values insum_rangefor the rows whererangemeets the condition:=SUMIF(region, "North", amount) total revenue from northern orders =SUMIF(amount, ">100", amount) total of all orders over 100
COUNTIF answers āhow many meeting Xā; SUMIF answers āthe total of Y for rows
meeting X.ā Together they compute the conditional counts and totals that most
analytical questions reduce to.
Multiple conditions: COUNTIFS and SUMIFS#
For several conditions at once, the plural forms COUNTIFS and SUMIFS take
multiple range-condition pairs:
=COUNTIFS(region, "North", amount, ">100")
=SUMIFS(amount, region, "North", month, "January")
COUNTIFS counts rows meeting all the conditions (northern and over 100);
SUMIFS sums for rows meeting all conditions. These handle the segmented
questions ā āJanuary revenue in the northern regionā ā that a single condition
cannot express, and they are the workhorses of spreadsheet analysis.
Why conditional aggregation matters#
Most analytical questions are conditional: not ātotal salesā but āsales in this
segmentā, not āhow many ordersā but āhow many of this typeā. COUNTIF and
SUMIF (and their plural forms) are how a spreadsheet answers these directly,
without first filtering the data by hand. They are also the conceptual bridge to
SQLās WHERE plus aggregate and to pivot tables ā the same āaggregate a subsetā
idea in three forms, which is why recognising the pattern here pays off repeatedly.
The caveat#
Conditional-aggregation functions are precise about their conditions, and small
mistakes mislead: a condition written as text must match exactly ("North" will
not catch "north" or "North " with a space ā the cleaning issues resurface),
and the condition syntax for comparisons (">100" in quotes) trips up beginners.
The ranges must also align ā SUMIFās condition range and sum range must be the
same size and correspond row-for-row, or the result is silently wrong. As always,
verify a conditional total against a hand-check or an order-of-magnitude estimate:
a SUMIF that returns an implausible number usually has a condition or range
error. The next lesson covers a more advanced calculation function: SUMPRODUCT.
Hint
See also
Source article Adapted (context, re-expressed) in our own words from: https://insightful-data-lab.com/2023/11/26/using-countif-and-sumif-for-conditional-aggregation-in-spreadsheets/ (insightful-data-lab.com).