vlookup with 2 criteria and date range

Blabla2a

New Member
Joined
Nov 21, 2016
Messages
9
Hey everyone,

I'm new here and I have a question.
I have 2 tables in excel

1. sales table
2. promotion table

in the sales table I have : Serial number , date , price , discount
in the promotion table I have: Serial number , start date, end date, discount

now I want to check if the discount in the sales table is like in promotion table!
remember you can find the same serial number in the promotion/sales date but in different dates.

I have to check if the
date(sales table) is between start date(promotion table) and end date(promotion table)
AND
serial number = serial number

if yes I want to put the discount(promotion table) in the sales table

I hope you understand me!

I try to do it in excel but it's stuck with more 750k lines

do you have any sql or via solution?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Could you post a sample of your work showing what you're trying to achieve?
 
Upvote 0
bar.jpg
Could you post a sample of your work showing what you're trying to achieve?
 
Upvote 0
Try the below formula (you can copy/paste the below data into excel).

Please keep in mind that the parameters are greater than or equal to and less than or equal to. Therefore if a start date is 1/1/2009 from the promotional table, and the date from the sales table is 1/1/2009 then it will populate percentages, same goes for end dates.

E2:
Code:
=IFERROR(IF(AND($C2>=VLOOKUP($A2,$G$2:$H$5,2,0),$C2<=VLOOKUP($A2,$G$2:$I$5,3,0)),VLOOKUP($A2,$G$2:$J$5,4,0),"0 / None"),"S/N Not Found")

S/NPRICEDATEDISCOUNTWhat I needS/NSTART DATEEND DATEDISCOUNT
4232344221/1/201040.00%30.00%4232341/1/20091/2/201030.00%
1231231475/23/201220.00%0 / None1231234/2/20125/22/201220.00%
1241245477/15/201270.00%0 / None12412410/1/20086/5/200910.00%
893451206/5/201020.00%20.00%893451/1/20107/1/201020.00%

<tbody>
</tbody>
 
Last edited:
Upvote 0
Try the below formula (you can copy/paste the below data into excel):

E2:
Code:
=IFERROR(IF(AND($C2>=VLOOKUP($A2,$G$2:$H$5,2,0),$C2<=VLOOKUP($A2,$G$2:$I$5,3,0)),VLOOKUP($A2,$G$2:$J$5,4,0),"0 / None"),"S/N Not Found")

S/NPRICEDATEDISCOUNTWhat I needS/NSTART DATEEND DATEDISCOUNT
4232344221/1/201040.00%30.00%4232341/1/20091/2/201030.00%
1231231475/23/201220.00%0 / None1231234/2/20125/22/201220.00%
1241245477/15/201270.00%0 / None12412410/1/20086/5/200910.00%
893451206/5/201020.00%20.00%893451/1/20107/1/201020.00%

<tbody>
</tbody>
hey,
I have 750,000 lines in sales table and 7500 lines in promotion.
Its too much for excel , what can I do?
 
Upvote 0
If the below doesn't work, then I'm not sure. Maybe try Power Query, Access, or VBA?

Try bringing over the dates to the SALES TABLE (by the E2 formula below) and see if that helps with calculation times.

E2 (copied over to F2 and down):
Code:
=IFERROR(INDEX(J$2:J$5,MATCH($A2,$I$2:$I$5,0)),"S/N Not Found")

G2:
Code:
=IF(AND($C2>=$E2,$C2<=$F2),INDEX($L$2:$L$5,MATCH($A2,$I$2:$I$5,0)),"0 / None")

S/NPRICEDATEDISCOUNTStart DateEnd DateWhat I needS/NSTART DATEEND DATEDISCOUNT
4232344221/1/201040.00%1/1/20091/2/201030.00%4232341/1/20091/2/201030.00%
1231231475/23/201220.00%4/2/20125/22/20120 / None1231234/2/20125/22/201220.00%
1241245477/15/201270.00%10/1/20086/5/20090 / None12412410/1/20086/5/200910.00%
893451206/5/201020.00%1/1/20107/1/201020.00%893451/1/20107/1/201020.00%

<tbody>
</tbody>
 
Last edited:
Upvote 0
its not working well with 7500 promotion lines.
I put this code:
Code:
=IFERROR(IF(AND($C2>=VLOOKUP($A2,$G$2:$H$7371,2,0),$C2<=VLOOKUP($A2,$G$2:$I$7371,3,0)),VLOOKUP($A2,$G$2:$J$7371,4,0),"None"),"S/N Not Found")
 
Upvote 0
Hm, not sure what to tell you, sorry. Perhaps some other users could suggest a solution. :-\

You might need Power Query, Access, or <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-top-style: initial; border-right-style: initial; border-bottom-style: dotted; border-left-style: initial; border-top-color: initial; border-right-color: initial; border-bottom-color: rgb(0, 0, 0); border-left-color: initial; border-image: initial; cursor: help; color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; background-color: rgb(250, 250, 250);">VBA...</acronym>
 
Last edited:
Upvote 0
Hi, this is solved with a nested IF.
Assuming your sale table is in the array A1 to D5 (S/N, PRICE, DATE, DISCOUNT columns) and your promotion table in array G1:J6 (S/N, STARTDATE, END DATE, DISCOUNT this is the formula you want to apply:
=IF(C2>=H2,IF(C2<=I2,IF(A2=G2,D2,"None"),"None"),"None")
This will return the DISCOUNT value only if the date in sales table is within the range start/end date in promotion table AND if S/N is the same. Else it will return NONE
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,913
Members
451,730
Latest member
BudgetGirl

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