I have two sheets in one Google Sheets document:
| Key | Amount |
|-----|---------|
| ABC | 1 |
| DEF | 2 |
| GHI | 3 |
| Keys |
|-------|
| ABC |
| XYZ |
| JKL |
| GHI |
Now, I'd like to add the amounts in the rows of the first sheet but only where the key is contained anywhere in the second sheet. For the example above, the sum would be 4
(keys ABC
with amount 1
and GHI
with amount 3
).
I've been trying QUERY
, SUMIF
and VLOOKUP
but haven't been able to find a solution. Any help would be greatly appreciated!
Best Answer
VLOOKUP
searches forA2:A
inSheet1!A2:B
and returns2
nd column fromSheet1!A2:B
as it is eg.0
for not sortedLEN(A2:A)
checks how many entries are in the range which stopsARRAYFORMULA
after last entryARRAYFORMULA
makes sure that whole formula will not stop after 1st rowIFERROR
removes all errors if there is no match inVLOOKUP
partSUM
sums it all