Multi Criteria Index/Match to find nearest value

troglodyte

New Member
Joined
Sep 9, 2014
Messages
11
Hi all,

I need help with (what I'm sure is!) a basic Index/Match problem which I can't wrap my head around.

I need to find the closest 'Fixed Value' (Column C) which relates to the list of 'Actual Values' (Column D) in column E. The other criteria here is that the value must come from the same Grouping, i.e. The value in cell D2 is in Group A, the closest value returned must also be in Group A (as determined by the letters in column B).

So far in E2 I have returned the closest value overall (for all groups) but not the one which is closest to a 'Fixed Value' from Group A. How can I amend my formula (seen below) in E2 so that I can return only the nearest number from the relevant group? A second point I'd possibly like to add is that I would want the name (in Column A) to be returned instead of the number.

Code:
=INDEX($C$2:$C$100000,MATCH(MIN(ABS($C$2:$C$100000-D2)),ABS($C$2:$C$100000-D2),0))

Below is an example of what I have (I can't attach the file sadly).

[TABLE="width: 357"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Group[/TD]
[TD]Fixed Value[/TD]
[TD]Actual Value[/TD]
[TD]Closest Value[/TD]
[/TR]
[TR]
[TD]Harry[/TD]
[TD]A[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]156531[/TD]
[TD="align: right"]15665[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]B[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]466[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Charlie[/TD]
[TD]C[/TD]
[TD="align: right"]15665[/TD]
[TD="align: right"]132[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Henry[/TD]
[TD]D[/TD]
[TD="align: right"]651651[/TD]
[TD="align: right"]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Simon[/TD]
[TD]A[/TD]
[TD="align: right"]648[/TD]
[TD="align: right"]45618[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Alex[/TD]
[TD]D[/TD]
[TD="align: right"]351[/TD]
[TD="align: right"]156[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Larry[/TD]
[TD]D[/TD]
[TD="align: right"]984[/TD]
[TD="align: right"]168[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Marvin[/TD]
[TD]D[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]51[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Tim[/TD]
[TD]D[/TD]
[TD="align: right"]984561[/TD]
[TD="align: right"]681[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Jeremy[/TD]
[TD]A[/TD]
[TD="align: right"]894[/TD]
[TD="align: right"]3251[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Tom[/TD]
[TD]B[/TD]
[TD="align: right"]2516[/TD]
[TD="align: right"]259[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Pat[/TD]
[TD]B[/TD]
[TD="align: right"]5684[/TD]
[TD="align: right"]651[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Adam[/TD]
[TD]C[/TD]
[TD="align: right"]561[/TD]
[TD="align: right"]56[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Dave[/TD]
[TD]C[/TD]
[TD="align: right"]656[/TD]
[TD="align: right"]353[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Many thanks,
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try
=INDEX($C$2:$C$100000,MATCH(MIN(IF($B$2:$B$100000=B2,ABS($C$2:$C$100000-D2))),ABS($C$2:$C$100000-D2),0))
 
Upvote 0
Try
=INDEX($C$2:$C$100000,MATCH(MIN(IF($B$2:$B$100000=B2,ABS($C$2:$C$100000-D2))),ABS($C$2:$C$100000-D2),0))

You need to repeat the conditional clause(s) within MATCH's lookup_array, otherwise you're not guaranteed correct results. What's more, I think we also need to exclude the case for the person pertaining to the row in question, i.e.:

=INDEX($A$2:$A$15,MATCH(MIN(IF($B$2:$B$15=B2,IF($A$2:$A$15<>A2,ABS($C$2:$C$15-D2)))),IF($B$2:$B$15=B2,IF($A$2:$A$15<>A2,ABS($C$2:$C$15-D2))),0))

@troglodyte I've used an upper range reference of only 15. Do you really need to go as far as row 100,000? These formulas are likely to bring your computer to a near standstill if that is the case.

Regards
 
Upvote 0
Try
=INDEX($C$2:$C$100000,MATCH(MIN(IF($B$2:$B$100000=B2,ABS($C$2:$C$100000-D2))),ABS($C$2:$C$100000-D2),0))
Thanks for your help!

You need to repeat the conditional clause(s) within MATCH's lookup_array, otherwise you're not guaranteed correct results. What's more, I think we also need to exclude the case for the person pertaining to the row in question, i.e.:

=INDEX($A$2:$A$15,MATCH(MIN(IF($B$2:$B$15=B2,IF($A$2:$A$15<>A2,ABS($C$2:$C$15-D2)))),IF($B$2:$B$15=B2,IF($A$2:$A$15<>A2,ABS($C$2:$C$15-D2))),0))

@troglodyte I've used an upper range reference of only 15. Do you really need to go as far as row 100,000? These formulas are likely to bring your computer to a near standstill if that is the case.

Regards
Thanks for your input! The 100,000 was merely an effort to 'future-proof' this sheet for when it eventually grows to contain that much data (it most likely won't be 100,000 rows!). At present the sheet has just under 3,000 rows.

Once again thanks for your help here guys
 
Upvote 0
But array formulas calculate over all cells within the ranges passed to them, whether beyond the last-used cells in those ranges or not. So it's not like you can choose an arbitrarily large upper range reference with no detriment to performance: thought has to go into this choice.

And I take it you also noted my point about the error in gaz_chops' formula?

Regards
 
Upvote 0
But array formulas calculate over all cells within the ranges passed to them, whether beyond the last-used cells in those ranges or not. So it's not like you can choose an arbitrarily large upper range reference with no detriment to performance: thought has to go into this choice.

And I take it you also noted my point about the error in gaz_chops' formula?


Regards

I did notice -thank you, it works perfectly.
 
Upvote 0
You're welcome, as XOR LX pointed out, you should add it to the Match's lookup array, i missed it!

=INDEX($C$2:$C$15,MATCH(MIN(IF($B$2:$B$15=B2,ABS($C$2:$C$15-D2))),IF($B$2:$B$15=B2,ABS($C$2:$C$15-D2)),0))
 
Upvote 0
But I also think we need to exclude the row that the formula's in, no? Which is why I had the additional clause in my formula.

The reason is that we don't want the answer for e.g. "Harry" to be "Harry", correct? It has to be a different person.

Regards
 
Upvote 0
But I also think we need to exclude the row that the formula's in, no? Which is why I had the additional clause in my formula.

The reason is that we don't want the answer for e.g. "Harry" to be "Harry", correct? It has to be a different person.

Regards

You are correct, I was looking for a different person. Apologies for not making that clearer.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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