Via http://igoogledrive.blogspot.com/2013/07/google-spreadsheet-advanced-vlookup-and.html:
To calculate totalX, if 'Label' and 'Type' are column A on their respective sheets:
=sum(iferror(arrayformula(if(B2:B="";"";iferror(if(match(B2:B;'Sheet2'!A2:A4;0);vlookup(B2:B;'Sheet2'!A1:C4;{2}*sign(row(B2:B));false)))))))
And to calculate totalY:
=sum(iferror(arrayformula(if(B2:B="";"";iferror(if(match(B2:B;'Sheet2'!A2:A4;0);vlookup(B2:B;'Sheet2'!A1:C4;{3}*sign(row(B2:B));false)))))))
Use ISERROR
and IFERROR
to ignore empty cells and cells that aren't found. VLOOKUP
gets the actual values; {x}*sign
references the appropriate column in Sheet2.