Search code examples
google-sheetssumgoogle-sheets-querycountifgoogle-query-language

Using COUNTIF's & Total Sums In Google Sheets To Work Out A Financial Total Sum


I'm looking for a specific Google Sheets formula. I believe it's using COUNTIFS & SUMIF, but I can't work out how to do it, any help would be really appreciated.

So, my "C" column has a number of letter combinations in each cell... These are "FHG" "CS" "MO" and afew others. They are a reference to specific market trading strategies and I'm using this sheet to track every trade I make. So C3 may contain "FHG" C4, "MO" C5, "FHG", C6 "FHG" etc.

In the "I" column, there is a 'profit and loss' column which states how much was generated/lost for that particular row... These are formatted to currency.

At the top of my sheet, I have a summary list of each set of letters and I'm using a COUNTIF statement to work out the total number (instance count) of each particular letter combo and from there, I can work out strike rates, percentages etc.

The thing I can't work out is, 'is there a way to count/sum the relative numbers in the "I" column based on a specific letter combo?' For example, let's say running down today's trades, FHG appears on C3, C6, C8, C12, C16 etc. can I collect and sum the numbers (to create a total) from the corresponding P&L column, I3, I6, I8, I12, I16 etc?

My main aim is to have the following at the top in my "Summary Section":

'Letter Combo/Name Of Trading Technique' - 'Number Of Trades' (Using COUNTIFS down C Column) - 'Total % Win Rate' (Number Of Winners/Number Of Total Trades For Said Strategy - This is done using a separate column of Y or N for winners or losers) - The one that I need help with is - "Total Sum Of Money Generated For Each Particular Letter Combo (Trading Strategy)"...... I've worked out how to do the first 3 columns, but I can't work out how to pick the numbers out from the P&L column (I) based on what kind of trade (letter combo) exists in the corresponding (C) column.

If every trade made the same about of money, this would probably be an easy calculation, but because each return is different, this is proving challenging.

Thanks for any insights :)


Solution

  • try:

    =QUERY(A:I; "select C,sum(I) where A is not null group by C label sum(I)''")
    

    or just for SB:

    =QUERY(A:I; "select C,sum(I) where C = 'SB' group by C label sum(I)''")
    

    if you want a count too:

    =QUERY(A:I; "select C,count(C),sum(I) where A is not null group by C")