Vlookup options

rfinnegan

Board Regular
Joined
Mar 15, 2005
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hi All:
How can I get VLOOKUP to account for all items that match it, not just the first one? For example, if a PLU (Product Look Up code) is sold at 2 stores, I'd want to see the total of the 2 stores, not just the first one VLOOKUP found.

I can accomplish this using a SUMPRODUCT formula I have, but the data set (6 tabs with about 60K lines and 6 columns per tab) and report are so large (about 700 data points using vlookup), that what was taking VLOOKUP about 6 seconds to update is taking the SUMPRODUCT formula about 1 minute to update.

Here's a sample of the SUMPRODUCT formula. Week 1 is one of 6 tabs. E2 is the store name, H11 is the PLU.

=SUMPRODUCT(--(week2!$C:$C=$E$2),--(week2!$D:$D=$H11),week2!$F:$F)

Any help is appreciated.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try SUMIFS:

=SUMIFS(week2!F:F,week2!C:C,E2,week2!D:D,H11)

Incidentally, your SUMPRODUCT formula is probably slow because you're using entire column references. If you change $C:$C to $C$1:$C$1000 (or whatever your maximum row is), it will calculate much faster. Without an upper row reference, SUMPRODUCT is forced to check all 1,000,000+ rows.

SUMIFS is "aware" of what the last used row is, so using whole column references in SUMIFS is much more efficient. You can still use row references if you want though.
 
Upvote 0
Try SUMIFS:

=SUMIFS(week2!F:F,week2!C:C,E2,week2!D:D,H11)

Incidentally, your SUMPRODUCT formula is probably slow because you're using entire column references. If you change $C:$C to $C$1:$C$1000 (or whatever your maximum row is), it will calculate much faster. Without an upper row reference, SUMPRODUCT is forced to check all 1,000,000+ rows.

SUMIFS is "aware" of what the last used row is, so using whole column references in SUMIFS is much more efficient. You can still use row references if you want though.

SUMIFS is a range-processing function while SUMPRODUCT does array-processing. The latter has an overhead that obtains by converting a reference (range) to an array, an additional cost compared with SUMIFS.
 
Upvote 0
Yes, I'm sure that's true, and a major difference in the calculation time. But according to Microsoft:

https://msdn.microsoft.com/en-us/vb...-tips-for-optimizing-performance-obstructions

For functions like SUM, SUMIF, and SUMIFS that handle ranges, the calculation time is proportional to the number of used cells you are summing or counting. Unused cells are not examined, so whole column references are relatively efficient, but it is better to ensure that you do not include more used cells than you need. Use tables, or calculate subset ranges or dynamic ranges.

Based on that, my statement about SUMIFS knowing the last row is also true. So there are multiple reasons why SUMIFS would work faster.
 
Upvote 0
Yes, I'm sure that's true, and a major difference in the calculation time. But according to Microsoft:

https://msdn.microsoft.com/en-us/vb...-tips-for-optimizing-performance-obstructions



Based on that, my statement about SUMIFS knowing the last row is also true. So there are multiple reasons why SUMIFS would work faster.

I am aware of that claim (I re-invoked that myself many times). The thing is that it is hard to identify from the observed behavior the factors which determine that behavior.

Let's assume:

[1] A routine for recognizing the used range.

Does this routine fire up when a function (say SUMIF(S) is fed a whole column/row or with any reference?

Thus:
Fed with A:A, used A2:A100 >> A2:A100?
Fed with B1:B100, used B1:B10 >> B1:B10 or B1:B100?

[2] A routine for transforming a range into an array, e.g., A2:A10 >> {elements of A2:A10}

The thinking is that the code for SUMIFS includes [1] but not [2] because it does not do array-processing, while the code for SUMPRODUCT does not include [1] while it must include [2].

[3] The cost associated with [2] > the cost associated with [1].

Looks like transform(used(range)) is avoided, that is, SUMPRODUCT does always transform(range).
 
Upvote 0
does changing C:C to C1:C100000) and D:D to D1:D100000) speed things up any

I tried something similar to that earlier and didn't notice a difference. I chose C:C and D:D because we are transitioning to a new system system which will increase the number of PLUs for the next couple of months. Problem is, I don't know how many PLUs there will be.

Thanks
 
Upvote 0
Try SUMIFS:

=SUMIFS(week2!F:F,week2!C:C,E2,week2!D:D,H11)

Incidentally, your SUMPRODUCT formula is probably slow because you're using entire column references. If you change $C:$C to $C$1:$C$1000 (or whatever your maximum row is), it will calculate much faster. Without an upper row reference, SUMPRODUCT is forced to check all 1,000,000+ rows.

SUMIFS is "aware" of what the last used row is, so using whole column references in SUMIFS is much more efficient. You can still use row references if you want though.

Worked perfectly, thanks a million. I knew the entire column reference was going to take time, but we are transitioning to a new system and I don't know what the upper limit is. What I do know is that it is about 60K now and will increase before old PLUs are purged and it gets down to about 35-45K.
 
Upvote 0
Worked perfectly, thanks a million. I knew the entire column reference was going to take time, but we are transitioning to a new system and I don't know what the upper limit is. What I do know is that it is about 60K now and will increase before old PLUs are purged and it gets down to about 35-45K.

You can switch to dynamic named ranges.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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