Complicated Match/Lookup in between dates formula?

jwillits

New Member
Joined
Jul 10, 2018
Messages
38
Office Version
  1. 2010
Platform
  1. Windows
Objective: I am trying to obtain a number (ID) from Table A based off of the Date and Number in Table B. What I am trying to say in my formula is that if Phone Number in Table B is equal to a Phone Number in Table A, and the Date in Table B in the same row as that Phone Number is between the Start and End Date in Table A, then I want the corresponding ID from Table A generated in the first column in Table B.

Furthermore, if the phone number matches but it does not fall between a one of the list of dates, I need it to pull the ID from the closest range of dates before it.

For instance, the last row in Table B has a Master Date of 4/22/19, however there is no date range in Table A for it, so it is pulling the ID from the date ranges of 3-26-19 to 4-1-19 because it is the closest date ranges before the master date.

Hopefully this makes sense and there is some wizard out there who can accomplish this. Multiple formulas building on each other is fine as well.





Table A

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Name[/TD]
[TD]ID[/TD]
[TD]Date Start[/TD]
[TD]Date End[/TD]
[TD]Phone Number[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64"]Apple[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]375[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]12/30/2018[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]1/5/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-908-5231[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Pear[/TD]
[TD]224[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]12/30/2018[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]1/5/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-8442[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Grape[/TD]
[TD]846[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]3/26/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]4/1/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-5592[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]Lemon[/TD]
[TD]552[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="class: xl65, width: 108, align: right"]5/26/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 102"]
<tbody>[TR]
[TD="class: xl65, width: 102, align: right"]6/1/2019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-5592[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



Table B

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Master Date[/TD]
[TD]Phone Number[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]224[/TD]
[TD]1/3/19[/TD]
[TD][TABLE="width: 122"]
<tbody>[TR]
[TD="width: 122"]210-361-8442[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]846[/TD]
[TD]3/27/19[/TD]
[TD]210-361-5592[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]846[/TD]
[TD]4/22/19[/TD]
[TD]210-361-5592[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this Array formula on sheet1

{=IFERROR(INDEX('Weekly Run Spots'!$E$2:$E$14,MAX(IF(('Weekly Run Spots'!$O$2:$O$14=E2)*('Weekly Run Spots'!$K$2:$K$14<=C2)*('Weekly Run Spots'!$L$2:$L$14>=C2),ROW('Weekly Run Spots'!$A$2:$A$14)))-1),IFERROR(INDEX('Weekly Run Spots'!$E$2:$E$14,MAX(IF(('Weekly Run Spots'!$O$2:$O$14=E2)*('Weekly Run Spots'!$L$2:$L$14=MAX(IF('Weekly Run Spots'!$L$2:$L$14<C2,'Weekly Run Spots'!$L$2:$L$14))),ROW('Weekly Run Spots'!$A$2:$A$14)))-1),"Number not exists"))}

Notes:
- The dates on sheet1 in column C must contain only the date, they currently have date and time.
- Change 14 in all ranges of the formula for the last row with data from the "Weekly Run Spots" sheet.


Attach the file with the test:

https://www.dropbox.com/s/2vbrgjftqdhu822/Sample Data.xlsx?dl=0
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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