Search code examples
excelexcel-formulasumcategoriessumifs

How do I sum several rows by category? (EXCEL)


I have created an excel sheet to have an overview over costs in my projects, however, I also need an overview of costs per category in my projects. I googled it and tried to find examples online, however, it only returns a value of 0, which shouldn't be the case. Can anyone help me? The sheet looks like below.

Excel Sheet

I am going by the SUMIF function to group by category but my excel sheet is a bit more complex than that so I tried to adjust it accordingly as seen in the code below. No matter what I do it either returns an error or 0.

=IF(B12=B8;"";SUMIF(B12:B39;B12;J12:BE39))

In the formula above I am trying to sum the costs of a category that could be written in B12, for example, Software development. For confidential reasons, I cannot show the actual filled out excel sheet.


Solution

  • sumif does not work with summing multiple columns. Instead use a sumproduct statement instead like so:

    =IF($B12=$B$8;"";SUMPRODUCT(($B$12:$B$39=$B12)*($J$12:$BE$39)))
    

    A detailed explanation to how this works can be found here

    Edit: I sense a follow up question coming, how to skip certain columns. Because as you have set it up now, it will count the entire range from J12 to BE39, in which you have both forecast costs and actual costs. I guess this is to compare the costs to what was projected and what the actual costs are. Right now it will count both the projected and actual cost, doubling up. To prevent this you can enter every second column separated by a + like so:

    =IF($B12=$B$8;"";SUMPRODUCT(($B$12:$B$39=$B12)*($J$12:$J$39+$L$12:$L$39+$N$12:$N$39)))
    

    Also I have added $ signs to all non-changing values so it will work when dragging down the fill handle on the formula to populate the below cells.