Index Match Two-Way Lookup Help

sole32

New Member
Joined
Aug 25, 2023
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
  3. Web
Hello,

I am trying to do a two-way lookup of a matrix table using index match given two things:
  1. Year
  2. Value
Since the table is basically just a range of values per year, I also need to apply closest match to determine which is the best category to assign to the provided value.

See below for a sample of the table:

Row 1 contains the years going back to 1998.
Beneath the year, are the values themselves.

And Column A contains the category (1-16) that I need to return.

202420232022200019991998
11009995555148
2999790524944
3969386504739
14878568222016
15838160191815
16807856161512

As mentioned above, I am given Year and Value.
Need to return the category (Col A) that is closest based on the table.

Example:
YearProvided ValueCategory
202391Should return 3 here
202287Should return 3 here
199815Should return 14 here


This would work perfectly if I only had one year of data to lookup (i.e. 2023):
=index(Table!$A$2:$A$17,match(min(abs(Table!$C$2:$C$17-$C3)),abs(Table!$C$2:$C$17-$C3),0)))

Unfortunately my dataset spans all 25+ years.

Any thoughts on how to do this using index match?
Feel like I'm kind of on the right track with the above formula, but struggling right now to incorporate the two-way lookup.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the MrExcel board!

Shouldn't the last result be 15?

Anyway, see if this helps. You will have to adjust the ranges/sheet names to suit your actual layout.

23 08 26.xlsm
ABCDEFGHIJ
1202420232022200019991998
211009995555148
32999790524944
43969386504739
5
6
7
814878568222016
915838160191815
1016807856161512
11
12
13YearValueCat
142023913
152022873
1619981515
sole32
Cell Formulas
RangeFormula
C14:C16C14=LET(y,ABS(FILTER(B$2:J$10,B$1:J$1=A14)-B14),INDEX(A$2:A$10,MATCH(MIN(y),y,0)))


Also, one further question: What should happen if two categories are equal closest match? For example: Year = 2022, Value = 88
In this case my formula above would return Category 2, but Category 3 is equally close. :unsure:
 
Upvote 0
Thanks for the reply.
And yes good catch! Last line in the example should return category 15.

Also, thanks for bringing up that use case.
For closest match where the value directly in-between two values, I would need to round down and return the category of the lower value.

What would need to be changed in the formula as a result?
 
Upvote 0
For closest match where the value directly in-between two values, I would need to round down and return the category of the lower value.

What would need to be changed in the formula as a result?
Is the column D formula what you mean?

23 08 26.xlsm
ABCDEFGHIJ
1202420232022200019991998
211009995555148
32999790524944
43969386504739
5
6
7
814878568222016
915838160191815
1016807856161512
11
12
13YearValueCatCat
1420239133
1520228733
161998151515
1720228823
sole32
Cell Formulas
RangeFormula
C14:C17C14=LET(y,ABS(FILTER(B$2:J$10,B$1:J$1=A14)-B14),INDEX(A$2:A$10,MATCH(MIN(y),y,0)))
D14:D17D14=LET(y,ABS(FILTER(B$2:J$10,B$1:J$1=A14)-B14),INDEX(A$2:A$10,XMATCH(MIN(y),y,,-1)))
 
Upvote 0
Thanks @Peter_SSs!

Both formulas appear to be working as intended (both in rounding up and down).
I'll do a more rigorous check tomorrow - but looks good to me.
 
Upvote 0
Sorry for digging this up again.
Previously, I was looking to get exact match or closest match in the range.
And for instances where the number fell directly between two values, then round down.

But the ask has changed somewhat.
Now, I am in need of exact match or if no exact match is found, then round down to the nearest value (regardless of how close another higher value may be).

So if this is the example data set:

202420232022200019991998
11009995555148
2999790524944
3969386504739
14878568222016
15838160191815
16807856161512

And this is the data given:
YearProvided ValueCategory
202391Should return 14 here (Need to round down even though #3 is closer)
202288Should return 3 here (Round down)
199815Should return 15 here (due to exact match)
 
Upvote 0
What would be the best way to handle this?

Is changing the previous index match viable?
Since the logic was updated, it seems that an amendment(s) would need to be made.
 
Upvote 0
Sorry, I have been away for a couple of weeks. Is this what you mean?

23 10 04.xlsm
ABCDEFG
1202420232022200019991998
211009995555148
32999790524944
43969386504739
514878568222016
615838160191815
716807856161512
8
9YearProvided ValueCategory
1020239114
112022883
1219981515
sole32 (2)
Cell Formulas
RangeFormula
C10:C12C10=XLOOKUP(B10,FILTER(B$2:G$7,B$1:G$1=A10),A$2:A$7,,-1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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