Match Date to Nearest Month + Match with text field

Caleeco

Well-known Member
Joined
Jan 9, 2016
Messages
980
Office Version
  1. 2010
Platform
  1. Windows
BCDEFGHIJ
1Year-MonthProductDateYear-MonthProductDateDefectsDesired output
2201909A15/09/2019201910A17/10/201913201909
3201907B29/07/2019201907D15/07/201915201906
4201907C28/07/2019201907C02/07/20194201907
5201907A01/07/2019201906A27/06/201914201806
6201906D05/06/2019201906B18/06/20198201907
7201906A03/06/2019201905E01/05/201913201905

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Hello,

Im struggling with a data-matching problem (which I can solve using VBA) but would prefer a formula solution.

Data Setup
  • Table 1 (Column B:D) is static data. Shows different products made each month (Year-Month)
  • Table 2 (Column E:J) is static data aside from Column J which needs to evaluate Table 1

The Problem
For each row I need Column J to look at Table 1 and ask the following questions:


  • Have I made Part X (Column B) in the same Month as the defects occured (Column H)? > If YES, return Matched YEARAP (From Table 1 or 2)
  • If I have not made Part X (Column B) in the same month as the defects occurred, find the nearest matching month that product was made > return that matched Year-AP (from Table 1)
  • If Part X is not found in Table 1, return Year-AP from Column F

Worked Example
Row 2 - Part A. Was not made in October (Table 1) > It is found in Table 1 > Nearest Matching month is September > Return 201909.


Is this possible? Any help is appreciated as always
Many Thanks

Caleeco
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,

I can't match all your desired results for the obvious reason being I don't see 201806 in any of your table's.
Take a look at this:


Book1
ABCDEFGHIJKL
11Year-MonthProductDateYear-MonthProductDateDefectsDesired outputFormula Output
22201909A15-9-2019201910A17-10-201913201909201909
33201907B29-7-2019201907D15-7-201915201906201906
44201907C28-7-2019201907C2-7-20194201907201907
55201907A1-7-2019201906A27-6-201914201806201907
66201906D5-6-2019201906B18-6-20198201907201907
77201906A3-6-2019201905E1-5-201913201905201905
Sheet2
Cell Formulas
RangeFormula
L2{=IFERROR(INDEX($B$2:$B$7,MATCH(INDEX(IF($C$2:$C$7=$G2,$D$2:$D$7,999999),MATCH(MIN(ABS(IF($C$2:$C$7=$G2,$D$2:$D$7,999999)-$H2)),ABS(IF($C$2:$C$7=$G2,$D$2:$D$7,999999)-$H2),0)),$D$2:$D$7,0)),F2)}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
Take a look at this:
I actually posted something along the same lines but then realised that it wasn't robust so removed it. I think the same occurs with yours - see J5 with my changed sample data below. By my understanding that should be 201906.

Excel Workbook
BCDEFGHIJ
1Year-MonthProductDateYear-MonthProductDateDefectsOutput
2202009Z15/09/2019201910X17/10/201913201910
3201907A15/09/2019201910A17/10/201913202009
4201907C28/07/2019201907C2/07/20194201907
5201909A1/07/2019201906A27/06/201914201909
6201906D5/06/2019201906B18/06/20198201906
7201906A3/06/2019201905E1/05/201913201905
Match Near (2)
 
Last edited:
Upvote 0
Hi @Peter_SSs

Thoughts are similar but i didn't change the request of the OP being "nearest date". If OP added "past nearest date" or had intention to ask but forgot to mention it, my solution isn't right.
Let's wait and see what OP comes back with.

Any way past nearest date can also be solved so ....
 
Upvote 0
Added to post #4 .


Book1
ABCDEFGHIJKLM
11Year-MonthProductDateYear-MonthProductDateDefectsDesired outputNearest DateNearest Past Date
22201909A15-9-2019201910A17-10-201913201909201909201909
33201907B29-7-2019201907D15-7-201915201906201906201906
44201907C28-7-2019201907C2-7-20194201907201907201907
55201907A1-7-2019201906A27-6-201914201806201907201906
66201906D5-6-2019201906B18-6-20198201907201907201906
77201906A3-6-2019201905E1-5-201913201905201905201905
Sheet2
Cell Formulas
RangeFormula
L2{=IFERROR(INDEX($B$2:$B$7,MATCH(INDEX(IF($C$2:$C$7=$G2,$D$2:$D$7,999999),MATCH(MIN(ABS(IF($C$2:$C$7=$G2,$D$2:$D$7,999999)-$H2)),ABS(IF($C$2:$C$7=$G2,$D$2:$D$7,999999)-$H2),0)),$D$2:$D$7,0)),F2)}
M2{=IFERROR(INDEX($B$2:$B$7,MATCH(MAX((IF($C$2:$C$7=$G2,$D$2:$D$7,999999))*IF($C$2:$C$7=$G2,$D$2:$D$7,999999)),$D$2:$D$7,0)),F2)}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
First, I had some errors in my sample data in that previous post so please ignore my comments there. I'll try again here.

Excel Workbook
BCDEFGHIJ
1Year-MonthProductDateYear-MonthProductDateDefectsOutput
2202009Z15/09/2019201910X17/10/201913201910
3201907A15/07/2019201910A17/10/201913201909
4201907C28/07/2019201907C2/07/20194201907
5201909A1/09/2019201906A27/06/201914201907
6201906D5/06/2019201906B18/06/20198201906
7201906A3/06/2019201905E1/05/201913201905
Match Near (2)




.. i didn't change the request of the OP being "nearest date".
Actually, the OP didn't request "nearest date" but ..
Have I made Part X (Column B) in the same Month as the defects occured (Column H)? > If YES, return Matched YEARAP (From Table 1 or 2)
So for that row 5 example, there was product A made in June 2019 so that should be the result.

And if there wasn't a product made in the same month, the request was ..
If I have not made Part X (Column B) in the same month as the defects occurred, find the nearest matching month that product was made > return that matched Year-AP (from Table 1)
.. not nearest date.

I'm not trying to be critical here, especially since I haven't been able to come up with a suitable formula, but trying to discuss to get more clarity. :)
 
Upvote 0
@Peter_SSs @jorismoerings

Sorry for the delayed response, I've been pretty ill this week!

Thanks you so much for both your solutions! They both work great, although Peter is closest to my original brief (closest month, not date).

Kind Regards
Caleeco :)
 
Upvote 0
Sorry for the delayed response, I've been pretty ill this week!

Thanks you so much for both your solutions! They both work great
You're welcome. Hope you are now fully recovered. :)
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,381
Members
448,888
Latest member
Arle8907

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