Two way lookup (Sumproduct or other faster way)

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,585
Office Version
  1. 365
Platform
  1. Windows
Source Data

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]Employee[/TD]
[TD]Item code.[/TD]
[TD]Items Sold[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]A[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]80[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]B[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]90[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD]A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]110[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD]B[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]120[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]


Output

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]A[/TD]
[TD="align: right"]80[/TD]
[TD="align: right"]110[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]B[/TD]
[TD="align: right"]90[/TD]
[TD="align: right"]120[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD]C[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Spreadsheet Formulas
CellFormula
G2=SUMPRODUCT(($A$2:$A$7=$F2)*($B$2:$B$7=G$1)*$C$2:$C$7)
H2=SUMPRODUCT(($A$2:$A$7=$F2)*($B$2:$B$7=H$1)*$C$2:$C$7)

<tbody>
</tbody>

<tbody>
</tbody>

Excel tables to the web >> Excel Jeanie HTML 4

I have used sumproduct function to get the number of items sold in G2 and H2. I would like to know if there is a faster way to do it? The sumproduct makes my worksheet quite slow as the data is quite huge.
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Assuming that combinations such as A and 1 can occur more than once and the intention is to collect (sum) items sold (i.e. quanties), you can set up a range processing formula (with SUMIFS) instead of one that does array processing (like with SUMPRODUCT)...

In G2 just enter, copy across, and down:

=SUMIFS($C$2:$C$6,$A$2:$A$6,$A2,$B$2:$B$6,G$1)

This is also faster.
 
Upvote 0
This looks to be a perfect candidate for a PivotTable.
Place the Employee field in the PivotTable Rows, Item Code in the Columns and Items Sold in Values (with Sum selected).
 
Last edited:
Upvote 0
Assuming that combinations such as A and 1 can occur more than once and the intention is to collect (sum) items sold (i.e. quanties), you can set up a range processing formula (with SUMIFS) instead of one that does array processing (like with SUMPRODUCT)...

In G2 just enter, copy across, and down:

=SUMIFS($C$2:$C$6,$A$2:$A$6,$A2,$B$2:$B$6,G$1)

This is also faster.
Thanks Aladin, the intention is to retrieve the value not sum it. The combination will occur only once; however, I don't know how to get the vlookup or index and match working so i used sumproduct.
 
Upvote 0
So, is there be a better function to be used, if the sum is not required ?
 
Upvote 0
Thanks Aladin, the intention is to retrieve the value not sum it. The combination will occur only once; however, I don't know how to get the vlookup or index and match working so i used sumproduct.

So, is there be a better function to be used, if the sum is not required ?

In G2 control+shift+enter, not just enter, copy across, and down:

=IFNA(INDEX($C$2:$C$6,MATCH($F2,IF($B$2:$B$6=G$1,$A$2:$A$6),0)),"")

Note. If your Excel does not list IFNA, replace it in the formula with IFERROR.
 
Upvote 0
Since the Index-match version which you gave is an array formula whereas your SUMIFS version is a non-array formula. So I am confused as to which will be faster.
 
Upvote 0
Since the Index-match version which you gave is an array formula whereas your SUMIFS version is a non-array formula. So I am confused as to which will be faster.

You can try to time these formulas. It's possibly the SUMIFS formula that is faster. Conceptually, the conditional INDEX/MATCH is the appropriate fit.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top