Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum cells in a column that have a specific value in a cell in their row

My table is as follows...

Timestamp | Category   | Cost 
--------------------------------
...       | Shopping   | 5
...       | Charity    | 10
...       | Dining     | 20
...       | Mortgage   | 1000
...       | Dining     | 30
etc...

What I need is a formula for each category value that will get the sum of the cost column for rows that have that category. ie. total spending in that category that I can place in the "actual spending" cell in my budget table. The data is input with a google form so I have almost no power over formatting.

Thanks for your help!

like image 434
Travis L Avatar asked Sep 18 '12 00:09

Travis L


People also ask

How do I sum cells based on value in another cell?

For example, the formula =SUMIF(B2:B5, "John", C2:C5) sums only the values in the range C2:C5, where the corresponding cells in the range B2:B5 equal "John." To sum cells based on multiple criteria, see SUMIFS function.

How do I sum only certain cells in a row?

Just organize your data in table (Ctrl + T) or filter the data the way you want by clicking the Filter button. After that, select the cell immediately below the column you want to total, and click the AutoSum button on the ribbon. A SUBTOTAL formula will be inserted, summing only the visible cells in the column.


2 Answers

You could use multiple SUMIF() functions to place these sums anywhere in the spreadsheet. Assuming Column A is TimeStamp, Column B is Category, and Column C is Cost:

Shopping -> =SUMIF(B:B, "Shopping", C:C)
Charity  -> =SUMIF(B:B, "Charity", C:C)
Dining   -> =SUMIF(B:B, "Dining", C:C)
Mortgage -> =SUMIF(B:B, "Mortgage", C:C)
like image 90
T0t3sMcG0t3s Avatar answered Sep 21 '22 13:09

T0t3sMcG0t3s


Two options I see here. Pivot table is by far the fastest and easiest in my opinion. (See option 1 in image.)

or

If you know all the categories and have a specific place you want them... See option 2. This uses the command SumIf (Conditional summing) where it uses the value in column J and uses aggregation to sum all costs together.

enter image description here

like image 23
xQbert Avatar answered Sep 21 '22 13:09

xQbert