Google-sheets – Google sheets: summing cells in a column where the cell above contains a string

google sheets

I'd like to sum the cells in a column where the cell above contains a string. For example, sum all the cells where the cell directly above contains the string "Transport".

For example, in the following (which I have just inserted the correct numbers into), the 'Total transport' cell contains 42 as it is the sum of 10 + 20 + 12, from those cells with the string 'Transport' above them.

enter image description here

Best Answer

You can use do it in several steps :

  • check if condition is met
  • set value accordingly
  • sum all

Using =IF (logical_test, [value_if_true], [value_if_false])

enter image description here

=IF(A1="hello", A2,0) - this will set the values in the B column according the existence of a string. Than you can use =SUM(B2:B12).