Google Sheets – Subtract Range of Values by Matching Column Entries

formulasgoogle sheets

I made two queries(using =QUERY) to a range of data in google sheets with the results as per the image below

enter image description here

I would like to:

  1. subtract the values of the right/smaller table from the left/bigger table according to the
    matching column entries (B,GBP)
  2. add the column entry(ies) of the right/smaller table that are missing from the left/bigger table

with the desired result looking like :

enter image description here

Best Answer

Try this:

=query({query(A2:B7);query({D2:E5},"select Col1, -1*Col2 label -1*Col2 ''")}, "select Col1,Sum(Col2) group by Col1 Label Sum(Col2) 'Sum'")


Snapshot3