Search code examples
google-sheetsgoogle-sheets-formulavlookup

Sum multiple possible values in VLOOKUP on Google Spreadsheet


I have a table with several fields in Google Spreadsheet. Three of the are called Code, Price and Quantity.

I made an "special hidden" column to show the PRODUCT() of Price and Quantity (called SubTotal).

In another place I have a another little table with two fields: Code and Total.

I want to populate Total with the SUM() of every Subtotal with the same Code.

So I made a function like this:

=VLOOKUP(B4;I5:M17;5;false)

to get the Subtotal and it works, but only for one item.
The items on Code can be repeated so I want the SUM() of every subtotal, so I tried with:

=SUM(ARRAYFORMULA(VLOOKUP(B3;I5:M17;5;false)))

but returns the same than the first one, only 1 item, the first one that founds.

I'm expecting get the SUM() of every item in subtotal by code, but also I want to know if I can do this without using the column SubTotal, like made the product inside the formula, which is something I could not do also.


Solution

  • I finally used FILTER:

    =SUM(FILTER($M$5:$M$20;$I$5:$I$20=$B3))