I don't know how Google's spreadsheet works but a formula like this might be what you are looking for using the cell references in your displayed worksheet.

Formula: copy to clipboard
=G6-SUMIFS($G$3:G5,$D$3:D5,"goog",$C$3:C5,"Buy")