Finding the Nth Smallest Position

ModelMad

New Member
Joined
Jan 23, 2024
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello,

Thanks for reading. For a model i am working on i need to move activity from one building to the nth closest match which matches a specified criteria. I think i need to use the SMALL function to return the position of the smallest distance which matches my criteria, i can then offset this to the Unique ID of that site which is positioned above. Note i can't use the MATCH function as sometimes the postcodes are the same but the buildings are different (and do not match my criteria) and Match will return the first match only.

My formula below is consistently returning criteria matches but not the nth closest:

=OFFSET('Postcode Distance Matrix'!$F$7,-3,SMALL(IF(('Postcode Distance Matrix'!$G$3:$BR$3='Space Required Pivot '!$G10)*('Postcode Distance Matrix'!$G12:$BR12), COLUMN('Postcode Distance Matrix'!$G$3:$BR$3)-COLUMN('Postcode Distance Matrix'!$G12)+1), K$3))

Postcode Distance Matrix G3:BR3 - matching criteria
Space Required Pivot G - Matching criteria
Postcode Distance Matrix G12:BR12 - contains distance between buildings

Any idea how i can amend my formula to consistently return the nth smallest match??
 
Ok, how about
Excel Formula:
=INDEX(SORT(FILTER(VSTACK($B$3:$F$3,B4:F4),$B$2:$F$2=J4),2,,1),1,K$2)
This works perfectly, a very elegant solution indeed. Thanks to all for their efforts! I shall try and lurk on here to repay the favour.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,988
Members
449,093
Latest member
Mr Hughes

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