turbolek
turbolek

Reputation: 39

Google Sheets: adding cells to sum when condition is met

What formula should I use in Google Sheets to get a sum of multiple cells, where every cell has an independent condition determining wether it should be included in the sum or not. Something like this:

result = 0 + (IF(condition1, A1)) + (IF(condition2, B1)) + (IF(condition3, C1))

Upvotes: 0

Views: 659

Answers (2)

turbolek
turbolek

Reputation: 39

Turns out it works the way I posted in Original Question:

result = 0 + (IF(condition1, A1)) + (IF(condition2, B1)) + (IF(condition3, C1))

BUT you need to use a different parameter separator if comma (,) is used as a decimal point separator in your language. For Polish I had to use semicolon (;)

result = 0 + (IF(condition1; A1)) + (IF(condition2; B1)) + (IF(condition3; C1))

Upvotes: 0

ale13
ale13

Reputation: 6062

Depending on your conditions, you can use something similar to this:

=SUM(IF(A1<>0,A1,0),IF(B1<10,B1,0),IF(C1<10,C1,0),D1)

formula with example

Therefore, as a general example, you can simply make use of the SUM and the IF functions:

=SUM(IF(CONDITION1,A1,0),IF(CONDITION2,B1,0),IF(CONDITION3,C1,0)...)
  • the elements of the SUM function are separated by a comma;

  • the IF returns the first value if the condition is met and the second one if the condition is not met.

Reference

Upvotes: 1

Related Questions