Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I have data like in the following table:

+---+-----+-----+
| A | B   | C   |
+---+-----+-----+
| 0 | 5   | 30  |
| 1 | 0   | 30  |
| 0 | 15  | 40  |
| 1 | 0   | 40  |
| 1 | 10  | 50  |
+---+-----+-----+

Column A is a flag (true = 1, false = 0) so we only add up rows with flag==1
Column B is a "tax" to remove from the amount in Column C
So basically here, the total would be 110:

(we don't count row 1)
30-0
(we don't count row 3)
40-0
50-10

How do I do it in Google Spreadsheet?

share|improve this question
    
Haven't you been able to find any close examples here on Web Applications? –  Jacob Jan Tuinstra Jun 2 '13 at 17:42

2 Answers 2

up vote 1 down vote accepted

If you add the following formula in C7 with sum written in B7, then the total will be calculated the way you want:

=SUM(ARRAYFORMULA(IF(A2:A6=1;C2:C6-B2:B6,0)))

share|improve this answer

I would add a fourth column for the calculated line item result (using an if statement) and then do a simple =sum() at the end.

Make a new column to the right of C. Add this if statement:

=if(A1=0, C1, C1-B1)

Then sum col C.

share|improve this answer
    
Your total equals 180 and not 110 !! The formula should have been like this: =if(A2=0, 0, C2-B2). –  Jacob Jan Tuinstra Jun 2 '13 at 17:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.