LOOKUP IF value in range between two columns - return value in third column

londonpublish

New Member
Joined
Nov 23, 2012
Messages
1
Hello all,

First post on here so apologies if I miss any protocol. I'd greatly appreciate help with the following, which will save a lot manual checking!

So I have two data sets - an extract of the first as follows, demonstrating the periods for which products were promoted and the applicable discount in that promotional period. Note that any one product does not have overlapping promotional periods, although different product codes may have overlapping dates:

Set A:

Product CodePromotion Start DatePromotion End DateDiscount
10101/01/201231/03/20125%
10101/05/201230/06/201220%
11015/01/201231/03/20128%
11010/05/201230/06/201210%
11001/09/201231/10/201212%
15001/01/201231/03/201211%
15001/06/201230/06/201215%

<tbody>
</tbody>

I then have a listing of product codes and invoice dates, as follows:

Set B:

Product CodeInvoice Date
10128/02/2012
10125/03/2012
10106/05/2012
11025/01/2012
11001/10/2012
15010/01/2012

<tbody>
</tbody>

I would like to bring back the appropriate discount for the invoice date, so results as follows:

Set B:

Product CodeInvoice DateDiscount
10128/02/20125%
10125/03/20125%
10106/05/201220%
11025/01/20128%
11001/10/201212%
15010/01/201211%

<tbody>
</tbody>

I'm guessing that the first step to resolve this is to concatenate the codes with the VALUE of the DATES, so I have a range, as follows:

Set A:

Code-Start DateCode-End DateDiscount
10140909101409995%
101410301014109020%
11040923110409998%
110410391104109010%
110411531104121312%
150409091504099911%
150410611504109015%

<tbody>
</tbody>

And then do the same with my other set:

Set B:

Code-Inv DateInvoice Date
1014096728/02/2012
1014099325/03/2012
1014103506/05/2012
1104093325/01/2012
1104118301/10/2012
1504091810/01/2012

<tbody>
</tbody>

But how do I now look back from Set B to Set A to say, IF CODE-INV DATE is greater than a value in CODE-START DATE column and less than a value in CODE-END DATE column, return the discount value against that range?

Many thanks in advance.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to MrExcel.

What version of Excel do you have? If it's Excel 2007 or above you can use a formula like this with your original data:

=IFERROR(INDEX(D$2:D$8,MATCH(1,INDEX((A$2:A$8=F2)*(B$2:B$8<=G2)*(C$2:C$8>=G2),),FALSE)),0)

Otherwise you can use:

=IF(ISERROR(INDEX(D$2:D$8,MATCH(1,INDEX((A$2:A$8=F2)*(B$2:B$8<=G2)*(C$2:C$8>=G2),),FALSE))),0,INDEX(D$2:D$8,MATCH(1,INDEX((A$2:A$8=F2)*(B$2:B$8<=G2)*(C$2:C$8>=G2),),FALSE)))

where Set A is in the range A1:D8 and Set B is in the range F1:G7.
 
Upvote 0
What you need can be done using an array formula, such as this:

=MAX(IF((invoice data cell>=promotion start range)*(invoice date cell<=promotion end range);1;0)*discounts range)

The formula assumes that if there are 2 promotions at the same time, the better one is applied.

Make sure you enter the formula with ctr+shift+enter for it to work.

Hope this is clear enough and helps.
 
Upvote 0
Hi Andrew,

Could you explain why the MATCH argument has "1" in the "LookUp Value"?

Also, why is the nested INDEX function incomplete? There is a , before the bracket ends.

Regards,
Caleb
 
Upvote 0
Welcome to MrExcel.

The INDEX function returns an array of 1's and 0's from the boolean multiplication in its first argument. The second argument is effectively zero. MATCH returns the position of the first 1 in the array.
 
Upvote 0
Ah okay - Thanks for clarifying. I figured the 1 and 0's but was unsure of what the second argument being incomplete meant.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

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