← All how-to recipes

How to sum values by category (conditional sum) with SUMIF

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Add up only the numbers whose row matches a category or label, e.g. total spend for 'Books'.

The formula

AppFormulaNotes
Excel=SUMIF(A2:A6,"Books",B2:B6)Works in all Excel versions.
Google Sheets=SUMIF(A2:A6,"Books",B2:B6)Identical syntax.
LibreOffice Calc=SUMIF(A2:A6,"Books",B2:B6)Fully supported.

How it works

SUMIF(range, criteria, sum_range) adds every value in sum_range whose matching cell in range meets the criteria. Here the three 'Books' rows (10 + 7 + 2) total 19. For multiple conditions, use SUMIFS.

Verified, not just documented

We ran =SUMIF(A2:A6,"Books",B2:B6) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 19 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 19 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run Excel.

Functions used

SUMIF — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons