'Vlookup duplicates + IF to return a value

I have 2 columns I am trying to populate in my sheet using vlookup. One column is the buy amount and one is the sell amount. I am using 1 unique ID to lookup into my lookup file.

However the data I am looking up has duplicate IDs, with a measure name in one column and the value in another column. The values are showing twice due to buy and sell amount names.

Looks something like this:

ID    Measure Name     Measure value
1      Buy              1000
1      Sell             2000
2      Buy               5000
2      Sell              10000

How can I vlookup both and populate both to my sheet like this:

ID    Buy Amount     Sell Amount
1      1000            2000
2      5000            10000

I got this:

=IF(VLOOKUP(A2,valumeasure3!C:U, COLUMNS(C:U),FALSE),valumeasure3!E:E,0)

Not sure where to go from here, or if vlookup is even feasible.



Solution 1:[1]

As @ScottCraner mentioned, SUMIFS is the way to go here.

Applied to your specific situation, your formula should be this for the Buy value:

=SUMIFS(valumeasure3!$E:$E,valumeasure3!$C:$C,$A2,valumeasure3!$D:$D,"Buy")

And the for the Sell value:

=SUMIFS(valumeasure3!$E:$E,valumeasure3!$C:$C,$A2,valumeasure3!$D:$D,"Sell")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tigeravatar