# Find totals for each category based on categorization

I'm using numbers to categorize items in a list, each with a \$ amount.

Column A has a number, 1-15, depending on the item in column B. Column C has the cost of the item in column B.

I want to find the total cost of all the items with the number 1, same for number 2, and so on.

Use a Pivot Table - this tool is designed to solve just such tasks You could try query() in this way:

``````=QUERY(B2:C,"select B, sum(C) where B is not null group by B label B 'item'")
`````` Assuming your data is in `A2:C` with a header row on top of it in row 1, use `query()` like this:

`=query(A1:C, "select A, sum(C) where A is not null group by A", 1)`

The `1` specifies the number of header rows.

• OP said"I want to find the total cost of all the `items`", so I preferred (and I think it is better) to use column B and not A in the query, so that items appear in the result instead of numbers Aug 16 at 8:14
• Hmm... the OP also said "find the total cost of all the items with the number 1, same for number 2, and so on." Aug 16 at 8:19