ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Conditional math
  3. How to Count by Category in Excel

How to Count by Category in Excel

By ExcelReady Team·Updated November 2, 2026·7 min read

The short answer

To count by category in Excel, list each category once in a column, then use COUNTIF next to it: =COUNTIF($B$2:$B$9,F2) counts how many rows match the category in F2. Fill it down for the other categories. In Excel 2021 or Microsoft 365, =UNIQUE(B2:B9) builds the category list for you, and a PivotTable gives the same counts without formulas.

Key takeaways

  • COUNTIF(range, category) counts how many rows belong to one category.
  • Lock the range with $ signs before you fill the formula down a summary table.
  • UNIQUE builds the list of categories automatically in Excel 2021 and Microsoft 365.
  • Use COUNTIFS when a row must match a category and a second condition.
  • Check that the category counts add up to the total number of rows.
On this page+
  1. The sample data
  2. How to count one category with COUNTIF
  3. How to build a count by category table
  4. Build the category list automatically with UNIQUE
  5. How to count by category with a second condition
  6. Show each category as a percentage
  7. How to count by category with a PivotTable
  8. Why your category counts are wrong
  9. Practise it

To count by category in Excel, write each category once and put a COUNTIF formula next to it: =COUNTIF($B$2:$B$9,F2) returns how many rows belong to the category in F2. This guide is for anyone who needs a quick "how many of each?" table for a report or a job test. It covers the formula, an automatic category list with UNIQUE, a second condition, percentages and PivotTables.

The sample data#

All the examples use this small order list in A1:D9. Each order has one category:

ABCD
1OrderCategoryRegionAmount
21001FurnitureNorth420
31002OfficeSouth85
41003TechNorth1,200
51004OfficeNorth60
61005TechSouth950
71006FurnitureSouth310
81007OfficeNorth45
91008TechNorth700

The question is: how many orders are in each category? The answer should be Furniture 2, Office 3 and Tech 3.

How to count one category with COUNTIF#

COUNTIF counts the cells in a range that match one condition, so it can count one category at a time. The syntax is =COUNTIF(range, criteria):

Excel formula
=COUNTIF(B2:B9,"Office")

The result is 3 (orders 1002, 1004 and 1007). The range is the Category column, and the criteria is the category name in double quotes. COUNTIF ignores capitals, so "office" gives the same answer. The COUNTIF function guide lists every type of criteria it accepts.

How to build a count by category table#

A count by category table has one row per category and one COUNTIF per row. Point the criteria at a cell instead of typing the name, so one formula works for every row.

  1. In F1 type Category and in G1 type Count.
  2. In F2:F4 type Furniture, Office and Tech.
  3. In G2 type the formula below and press Enter.
  4. Select G2:G4 and fill down (Windows: Ctrl+D; Mac: ⌘D).
Excel formula
=COUNTIF($B$2:$B$9,F2)
FG
1CategoryCount
2Furniture2
3Office3
4Tech3

The $ signs lock the range, so it stays on rows 2 to 9 when you fill down. F2 has no $, so it becomes F3 and F4. To add the $ signs quickly, click inside the range and press F4 on Windows or ⌘T on a Mac.

The same layout works for totals. Swap COUNTIF for SUMIF and you get the total for each category instead of the count.

Build the category list automatically with UNIQUE#

UNIQUE returns each value in a range once, so you don't have to type the categories yourself. It needs Excel 2021 or Microsoft 365. In F2, type:

Excel formula
=UNIQUE(B2:B9)

The result spills (fills the cells below on its own) into F2:F4: Furniture, Office, Tech, in the order they first appear. Wrap it in SORT for A to Z order: =SORT(UNIQUE(B2:B9)). The UNIQUE function guide explains the optional arguments.

Then count every category in one formula. In G2, type:

Excel formula
=COUNTIF(B2:B9,F2#)

The # after F2 means "the whole spilled list". When a new category appears in column B, both lists grow by themselves. If you only want to know how many different categories there are, see how to count unique values.

How to count by category with a second condition#

Use COUNTIFS when each row must match the category and something else. COUNTIFS takes pairs of ranges and criteria, and a row is counted only when every pair matches. To count Tech orders in the North region:

Excel formula
=COUNTIFS(B2:B9,"Tech",C2:C9,"North")

The result is 2 (orders 1003 and 1008). Conditions on numbers work too. This counts Tech orders of 800 or more:

Excel formula
=COUNTIFS(B2:B9,"Tech",D2:D9,">=800")

The result is 2 (1,200 and 950). For a full grid, put categories down column F and regions across row 1, then use =COUNTIFS($B$2:$B$9,$F2,$C$2:$C$9,G$1) and fill it right and down. The mixed $ signs keep the category column and the region row fixed.

Show each category as a percentage#

To see each category's share, divide its count by the total number of rows. COUNTA counts all filled cells, so it gives the total:

Excel formula
=COUNTIF($B$2:$B$9,F2)/COUNTA($B$2:$B$9)

For Office, that is 3 / 8 = 0.375. Format the cell as a percentage (Windows: Ctrl+Shift+%; Mac: Control+Shift+%), then add one decimal place to show 37.5%. Furniture is 25% and Tech is 37.5%, which adds up to 100%.

How to count by category with a PivotTable#

A PivotTable counts by category without any formulas, which is handy for large lists.

  1. Click any cell in the data.
  2. Go to Insert > PivotTable and click OK to place it on a new sheet.
  3. Drag Category to the Rows area.
  4. Drag Order (or Category again) to the Values area.

If the field in Values holds text, Excel shows Count by default. If it holds numbers, like Order here, Excel shows Sum. Click the field in Values, choose Value Field Settings and pick Count. The PivotTable doesn't update on its own: right-click it and choose Refresh after the data changes.

Formulas update instantly and are what most job tests ask for. Practise the formula version with the pivot-style summary lesson.

Why your category counts are wrong#

If the counts don't add up to the number of rows, the category column usually has messy values. Check the total first: =SUM(G2:G4) should equal =COUNTA(B2:B9), which is 8 here.

  • Extra spaces. "Tech " with a trailing space doesn't match "Tech". Clean the column with TRIM.
  • Different spellings. "Furniture" and "Furnitures" are two categories to Excel. UNIQUE shows them both, which makes them easy to spot.
  • Blank cells. Rows with no category aren't counted by any COUNTIF. Count them with =COUNTBLANK(B2:B9).
  • Missing categories. A typed list can miss a category. UNIQUE never does.

Counting duplicates is a close cousin of this task; see how to count duplicates. If your categories are simple answers like Yes and No, the guide on counting Yes in Excel covers that case.

Practise it#

Try the exercise on this page first: it counts one category from a cell. Then practise COUNTIF in a live spreadsheet, where you type the formula and it checks it instantly, and move on to the pivot-style summary lesson to build a full count and total table by category.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

How many orders are in the Tech category? Click H2 and use COUNTIF on the Category column (B2:B9) with the category in G2, then press Enter.

fx
ABCDEFGHI
1
Order
Category
Region
Amount
2
1001
Furniture
North
420
Tech
3
1002
Office
South
85
4
1003
Tech
North
1200
5
1004
Office
North
60
6
1005
Tech
South
950
7
1006
Furniture
South
310
8
1007
Office
North
45
9
1008
Tech
North
700
10
11
12

Tip: The range to check comes first (B2:B9), then the cell that holds the category (G2), with no quotes.

Practise this in a lesson

LessonCOUNTIFCount the cells that match a condition, from exact words to number checks like ">=8".LessonPivot-style summary with formulasBuild a summary table like a pivot table with formulas: a sorted UNIQUE list of categories, then SUMIFS and COUNTIFS filled down beside it.Function guideCOUNTIFCount cells that match one condition with COUNTIF: text, numbers, wildcards and cell references. Real examples and a live exercise.Function guideUNIQUEList distinct values with Excel's UNIQUE, count them with COUNTA, or find items that appear only once. Examples plus a live exercise.

Frequently asked questions

How do I count items by category in Excel?

+

Type each category once in a column, then use =COUNTIF($B$2:$B$9,F2) next to the first one and fill it down. B2:B9 is the category column and F2 is the category to count.

How do I count by category without typing the categories?

+

In Excel 2021 or Microsoft 365, type =UNIQUE(B2:B9) to list each category once, then =COUNTIF(B2:B9,F2#) next to it. The # makes the count follow the list as it grows.

How do I count by category with two conditions?

+

Use COUNTIFS, which takes pairs of ranges and criteria. For example, =COUNTIFS(B2:B9,"Tech",C2:C9,"North") counts Tech orders in the North region.

Can a PivotTable count by category?

+

Yes. Put the category field in Rows and any text field in Values. Excel counts text fields by default. If it shows Sum, change it to Count in Value Field Settings.

Why don't my category counts add up to the total?

+

Usually a category is spelled two ways, has an extra space, or is missing from your list. Compare the sum of the counts with COUNTA of the category column to find the gap.

Sources

  • COUNTIF function - Microsoft Support
  • UNIQUE function - Microsoft Support
  • Create a PivotTable to analyze worksheet data - Microsoft Support

Written and checked by the ExcelReady Team. First published November 2, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. The sample data
  2. How to count one category with COUNTIF
  3. How to build a count by category table
  4. Build the category list automatically with UNIQUE
  5. How to count by category with a second condition
  6. Show each category as a percentage
  7. How to count by category with a PivotTable
  8. Why your category counts are wrong
  9. Practise it

Keep reading

Conditional math· 6 min read

How to Sum by Category in Excel

To sum by category in Excel, list each category once, then use SUMIF next to it: =SUMIF($A$2:$A$8,D2,$B$2:$B$8) adds the amounts in column B for the category named in D2. Fill it down for a full summary. In Excel 2021 or Microsoft 365, =UNIQUE(A2:A8) builds the category list for you, and a PivotTable does the same job without formulas.

Conditional math· 6 min read

How to Count Cells With Text in Excel

To count cells that contain text in Excel, use COUNTIF with an asterisk: =COUNTIF(B2:B8,"*"). The * wildcard matches any text, so numbers, dates and blank cells are not counted. COUNTA is different: it counts every cell that isn't empty, numbers included. To count one specific word, put it in quotes: =COUNTIF(B2:B8,"Yes").

Conditional math· 6 min read

How to Count Duplicates in Excel

To count duplicates in Excel, use COUNTIF. =COUNTIF($A$2:$A$8,A2) shows how many times the value in A2 appears; any result above 1 is a duplicate. To count every row that is part of a duplicate set in one cell, use =SUMPRODUCT(--(COUNTIF(A2:A8,A2:A8)>1)). Decide first whether you need repeated rows, extra copies or repeated values.

More on conditional math

  • Count and Sum Colored Cells in Excel
  • How to Count Unique Values in Excel
  • How to Count Yes, No and Ticks in Excel
  • How to Use COUNTIF in Excel (With Criteria Examples)
  • COUNTIF From Another Sheet in Excel
  • COUNTIF Between Two Numbers in Excel
All conditional math articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free