How Data Actually Works

Asking questions data can answer

Counting and adding up

COUNTIF counts the rows that match a condition, SUM adds up a column, and COUNT counts the numbers; always check the answer another way.

By the end of this lesson you can use COUNT, COUNTIF and SUM to answer a question, and check the answer by hand.

Why it matters

A formula gives the same answer for 60 rows or 60,000 rows, in less than a second. It also updates by itself when the data changes. This is the moment a spreadsheet starts working for you.

The idea in plain words

You met formulas in lesson 2.4: anything you type that starts with =. A function is a ready-made job inside a formula, with a name in capital letters. You tell it where to look and what to do.

Function: a named job a spreadsheet can do, such as SUM (add up) or COUNTIF (count the cells that match). You give it what it needs inside brackets.

Range: the cells a function looks at. H:H means all of column H. F2:F61 means F2 down to F61.

Three functions answer most counting questions:

Function What it does Example
COUNTIF(range, what) Counts the cells in the range that match =COUNTIF(H:H,"Cash") counts cash sales
SUM(range) Adds up all the numbers in the range =SUM(F:F) adds every quantity
COUNT(range) Counts how many cells hold a number =COUNT(F:F) counts the sales with a quantity

Equals sign, job, where to look, what to count. Press Enter, and the answer appears.

COUNTIF does not mind capital letters: "cash" and "Cash" count the same (Google Docs Editors Help, COUNTIF).

See it done

Question: how did Amara's customers pay this week, and which way was most common?

Data: Amara's tab, market-stall-week.csv (synthetic). Remove any filter first.

  1. Plan. Payment is a category (column H). Count the rows in each group with COUNTIF.
  2. Make a little results table in empty columns to the right. In J1 type payment, in K1 answer.
  3. Type the groups. J2 Cash, J3 Transfer, J4 Card.
  4. Type the formulas.

K2: =COUNTIF(H:H,"Cash") K3: =COUNTIF(H:H,"Transfer") K4: =COUNTIF(H:H,"Card")

  1. Read the answers. Cash 28, Transfer 20, Card 12.
  2. Check another way. Amara made 60 sales (you found this in lesson 1.5). And 28 + 20 + 12 = 60. Every sale was counted exactly once.
  3. Answer in a sentence. "Cash was the most common way to pay: 28 of Amara's 60 sales from 2 to 7 March 2026."

Three COUNTIFs, and a check that they add up to all 60 sales.

Now the total number of items. In K7 type =SUM(F:F). It gives 249: Amara handed over 249 fruits this week. =COUNT(F:F) gives 60, because column F has 60 numbers (one per sale; the name quantity in F1 is a word, so it is not counted).

Go further (optional): most items and most money, with SUMIF

SUMIF adds up only the rows that match. =SUMIF(E:E,"Orange",F:F) means: look in column E for "Orange", and add up the matching numbers in column F. It gives 103: the oranges sold this week.

Do the same for each fruit: Mango 50, Banana 28, Orange 103, Pawpaw 23, Pineapple 23, Watermelon 22. Orange wins "most items", as lesson 3.1 said.

For "most money", first make a money column:

  1. In I1 type money. In I2 type =F2*G2 (quantity times price) and press Enter.
  2. Click I2 and copy it (Ctrl + C, or ⌘ + C on a Mac). Select I3 down to I61 and paste (Ctrl + V). The pasted formula changes to match each row (I3 becomes =F3*G3, and so on), so each row now shows the money for that sale.
  3. =SUMIF(E:E,"Watermelon",I:I) gives 77000: ₦77,000. That is 22 watermelons × ₦3,500. The next best is Pineapple, with ₦34,500, so Watermelon wins "most money".

Your turn, with help

Which fruit had the most sales this week? Use one COUNTIF for each of the six fruits.

Hint: =COUNTIF(E:E,"Mango") counts mango sales. Change the fruit name for each one. Then check: do your six answers add up to 60?

Show the answer

Mango 10, Banana 4, Orange 13, Pawpaw 10, Pineapple 10, Watermelon 13. Check: 10 + 4 + 13 + 10 + 10 + 13 = 60.

Orange and Watermelon tie with 13 sales each, just as lesson 3.1 said.

Your turn, alone

Write the formula, then the answer.

  1. How many sales were on Thursday?
  2. How many sales had a quantity of 10 or more? (Hint: COUNTIF can test numbers: ">=10" means 10 or more.)
  3. In Lucía's tab, how many minutes do all 30 pupils spend travelling to school in total?
  4. In Lucía's tab, what does =COUNT(H2:H31) give, and why is it not 30?
Check your answers
  1. =COUNTIF(C:C,"Thu") gives 11.
  2. =COUNTIF(F:F,">=10") gives 5.
  3. =SUM(G2:G31) gives 600.
    1. COUNT only counts cells that hold a number. 4 pupils left siblings blank, so 30 − 4 = 26.

Watch out

  • Spelling and quotes. Words inside a formula need double quotes: "Cash". A typo like "Csah" gives 0, with no warning.
  • Counting the wrong thing. COUNT counts numbers. On a column of words, such as payment, it gives 0. Use COUNTIF to count words.
  • Trusting without checking. Always check one answer another way: do the groups add up to the total? Does a filter show the same number of rows? A second method catches most mistakes.

Say it back

  1. Which function counts the cells that match a condition?
  2. What does =SUM(F:F) do in Amara's sheet?
  3. Name one way to check a COUNTIF answer.
Show the answers
  1. COUNTIF.
  2. Adds up every quantity: the total number of fruits sold (249).
  3. Check the groups add up to the total, or use a filter and count the rows.

What is next

Amara now asks: "Which fruit makes me the most profit?" You have formulas, filters and sorting. Can you answer her? Next lesson.

Enjoying the free course?

Join the list and we will email you when new courses and launch offers go live. No spam.