complicated IF, INDEX, MATCH question

Status
Not open for further replies.

EP123

New Member
Joined
Dec 26, 2018
Messages
3
I have what I *think* is just a complicated IF/INDEX/MATCH problem that I have not quite been able to figure out. Hoping someone here can help.

I have two data sets which I am trying to merge. Dataset 1 contains a series of cases defined by a 9-digit serial number, a 4-digit ID number (this is needed as a unique identifier because the same serial # may appear multiple times in the set), a date, and a few columns of additional data. Dataset 2 contains 9-digit serial numbers, dates, and again, a few columns of (different) data. In this set, there are again multiple entries per serial number, but there is no unique identifying 4-digit ID number. The sets overlap completely in that they contain the same 9-digit serial numbers, but there are far more rows/entries in dataset 2.

To properly merge these sets, what I need to do is assign the right 4-digit ID number (along with corresponding date and data) from set 1 to the 9-digit serial numbers in set 2. Usually, for this type of problem, INDEX/MATCH is the solution I employ. However, what makes this a bit more complicated is that there are multiple unique 4-digit ID numbers for many of the 9-digit serial numbers (with the differentiating variable being a date), but simple INDEX/MATCH will only result in assigning one ID number to a given serial number. The right choice of ID number is a function of serial number AND date, and I cannot figure out how to create a formula to incorporate both of these properly.

Below I have provided some example data, including desired output. Basically, I want to match on serial number and merge "pet" data from dataset 1 with dataset 2 provided that the corresponding date for that entry in dataset 1 occurred before the date in for the ID number in dataset 2.

Example Set 1:
Serial #PetDate of Pet purchase
002241081cat3/23/2012
002241081dinosaur3/13/2013
002241081cow8/24/2010
002241081bird9/24/2013
002241081frog10/13/2010
002241081snake4/6/2012

<tbody>
</tbody>

Example Set 2:
ID #Serial #Date of scoreScore
10980022410816/21/2012 2R
20560022410813/6/20131R
11150022410816/18/2013 2R
22510022410817/25/20142R

<tbody>
</tbody>

Ideal merged table appearance (though other forms of merge would be ok if this is too difficult - I can make data more 'wide' later):
ID #Serial #Date of scoreScorePet 1Pet 2Pet 3Pet 4Pet 5Pet 6
10980022410816/21/2012 2Rcowfrogcatsnake
20560022410813/6/20131Rcowfrogcatsnake
11150022410816/18/2013 2Rcowfrogcatsnakedinosaur
22510022410817/25/20142Rcowfrogcatsnakedinosaurbird

<tbody>
</tbody>


Any help from experts or ambitious amateurs would be appreciated. Thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
copy to the right and down..


Excel 2016 (Windows) 32 bit
ABCDEFGHIJ
1Serial #PetDate of Pet purchaseID #Serial #Date of scoreScore
2002241081cat3/23/201210980022410816/21/20122R
3002241081dinosaur3/13/201320560022410813/6/20131R
4002241081cow8/24/201011150022410816/18/20132R
5002241081bird9/24/201322510022410817/25/20142R
6002241081frog10/13/2010
7002241081snake4/6/2012
8
9
10ID #Serial #Date of scoreScorePet 1Pet 2Pet 3Pet 4Pet 5Pet 6
1110980022410816/21/20122Rcatcowfrogsnake
1220560022410813/6/20131Rcatcowfrogsnake
1311150022410816/18/20132Rcatdinosaurcowfrogsnake
1422510022410817/25/20142Rcatdinosaurcowbirdfrogsnake
Sheet3
Cell Formulas
RangeFormula
E11{=IFERROR(INDEX($B$2:$B$7,SMALL(IF(($B11=$A$2:$A$7)*($C11>$C$2:$C$7),ROW($A$2:$A$7)-ROW($A$2)+1),COLUMNS($E$10:E10))),"")}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
from an ambitious amateur :ROFLMAO:

PS. the order from pet 1 to pet 6 is in the order from top to bottom in dataset 1
 
Last edited:
Upvote 0
Duplicate https://www.mrexcel.com/forum/excel...-problem-i-think-post5198078.html#post5198078

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

Note that sometimes posts from new users require Moderator approval before you can see them on the public forums. When this happens, you should see a message to that effect when you try to post it.
Please be patient and do not attempt to post the question again.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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