How to add numbers only if some other cell matches a particular criteria in Google Spreadsheets?

google-drive-api, google-sheets

Solution

The SUMIF criteria in Spreadsheet works as follows:

=SUMIF(range, criteria, sum_range)

whereby range is the range from which you want to match (C column in your example, which has Debit/Credit)

Criteria = what should match (Debit or Credit based on the formula in your example)

Sum_range = The Column that needs to be summed - (D column in your example)

So your formula should be somewhat

=SUMIF(C1:C1000,"D"&"*",D1:D1000) for Debit
=SUMIF(C1:C1000,"C"&"*",D1:D1000) for Credit

Note: you can use "Debit" or "Credit" in place of "D"&"" or "C"&"" respectively.

Problem

situation A spreadsheet to maintain accounts. A form as so: The form What I want to do I want to add the value in the column D if it has Type of transaction = Credit and If it has type of transaction = debit then I want to subtract it from the total. I am finding this total inside the spreadsheet itself. So I think `SUMIF(...,...,...)` will be used but I am not sure. Spreadsheet for reference. I guess: The criteria could be what is the first letter of the cell in column C which is in the same row as the cell now being considered which belongs to column D. If it is of the form `C*` then it is credit if it is of the form `D*` then it is a debit transaction. But I am unable to find out how to apply this condition.

Original source