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??
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
welcome to the Mr. Excel forum. The forum has a tool that allows you to share a mini portion of worksheets, called xl2bb add in, the link is below.
Please use this to share the data for your scenario. If you cannot use this, then please post a table of your data.

Expected results are always very helpful as well.

When not providing sample data (or posting an image) you're asking the forum to completely recreate (and guess in it too) your scenario. That can lead to errors and typos. It also means the forum members trying to solve your question will take more time in setting things up than a copy and paste.

Thanks in advance.
 
Upvote 0
You would need to share the content of the sheets "Required PC", "Available PC" and "Space Available Pivot" also.

And one other thing: You seem to have circular references in your sheet.
 
Upvote 0
Unfortunately there is too much sensitive info to post anything. If anyone has any tips on making returning the Position of the nth smallest number within a row which matches a criteria i am able to translate it into my formula. I just don't understand why the mechanics of what i have input are not returning the results i expect. e.g.

=OFFSET('Postcode Distance Matrix'!$F$7,-3,SMALL(IF(('Postcode Distance Matrix'!$G17:$BR17)*('Postcode Distance Matrix'!$G$3:$BR$3='Space Required Pivot '!$G15), COLUMN('Postcode Distance Matrix'!$G$3:$BR$3)-COLUMN('Postcode Distance Matrix'!$G17)+1), K$3)) returns the code of a site which is 9 miles away

=SMALL(IF(('Postcode Distance Matrix'!$G17:$BR17)*('Postcode Distance Matrix'!$G$3:$BR$3='Space Required Pivot '!$G15), COLUMN('Postcode Distance Matrix'!$G$3:$BR$3)-COLUMN('Postcode Distance Matrix'!$G17)+1), L$3) returns position 34 which is the same as above.

However:

=SMALL(IF(('Postcode Distance Matrix'!$G$3:$BR$3='Space Required Pivot '!$G15),'Postcode Distance Matrix'!$G17:$BR17), M$3) returns a 0 confirming my manual check that there is a suitable building in the same postcode.

Any comments would be very welcome
 
Upvote 0
How about something like this:
In column E list of filtered results (just to show them), and in cell F2 the complete formula with SMALL, getting the 3rd smallest value.

Book4
ABCDEF
1Criteria 1Cirteria 2Value to returnFiltered by criteria onlythird smallest
2a11111
3a122
4a2311
5a2412
6a25
7b16
8b17
9b28
10b29
11b210
12a111
13a112
14a213
15a214
16a215
17b116
18b117
19b218
20b219
21b220
22
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=FILTER(C2:C21,(A2:A21="a")*(B2:B21=1))
F2F2=SMALL(FILTER(C2:C21,(A2:A21="a")*(B2:B21=1)), 3)
Dynamic array formulas.
 
Upvote 0
How about something like this:
In column E list of filtered results (just to show them), and in cell F2 the complete formula with SMALL, getting the 3rd smallest value.

Book4
ABCDEF
1Criteria 1Cirteria 2Value to returnFiltered by criteria onlythird smallest
2a11111
3a122
4a2311
5a2412
6a25
7b16
8b17
9b28
10b29
11b210
12a111
13a112
14a213
15a214
16a215
17b116
18b117
19b218
20b219
21b220
22
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=FILTER(C2:C21,(A2:A21="a")*(B2:B21=1))
F2F2=SMALL(FILTER(C2:C21,(A2:A21="a")*(B2:B21=1)), 3)
Dynamic array formulas.
Thanks for the suggestion - i need to return the position of the value as opposed to just identifying it. the position is then combined with an OFFSET formula to provide the site's unique ID
 
Upvote 0
Are the values unique? If so, how about?:

Book4
ABCDEFG
1Criteria 1Cirteria 2Value to returnFiltered by criteria onlythird smallestIndex or postion
2a1101011011
3a12020
4a230110
5a240120
6a250
7b160
8b170
9b280
10b290
11b2100
12a1110
13a1120
14a2130
15a2140
16a2150
17b1160
18b1170
19b2180
20b2190
21b2200
22
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=FILTER(C2:C21,(A2:A21="a")*(B2:B21=1))
F2F2=SMALL(FILTER(C2:C21,(A2:A21="a")*(B2:B21=1)), 3)
G2G2=MATCH(SMALL(FILTER(C2:C21,(A2:A21="a")*(B2:B21=1)), 3), C2:C21, 0)
Dynamic array formulas.
 
Upvote 0
book1
ABCDEFGHIJKLMNOP
1
2CriteriaCACBCDCACF1
3Site CodeAAABACADAFSite CodeCriteriaFull FormulaExpected resultPosition Formula Position Expected ResultSmallest matching critera resultSmallest Expected
4BA0.100.300.200.050.90BACAAAAD140.050.05
5BA0.400.000.601.305.40BACD
6BB0.801.200.002.203.30BB
7BC0.904.500.100.000.40BC
8BD1.102.203.505.500.00BD
9
10
11
12
Sheet1
Cell Formulas
RangeFormula
K4K4=OFFSET(A3,0,SMALL(IF(($B$2:$F$2=$J4)*(B4:F4), COLUMN($B4:$F4)-COLUMN($B4)+1), K2))
M4M4=SMALL(IF(($B$2:$F$2=$J4)*(B4:F4), COLUMN($B4:$F4)-COLUMN($B4)+1), K2)
O4O4=SMALL(IF($B$2:$F$2=J4,B4:F4),K2)
A4:A8A4=I4


In the attached you will see my formula is failing to return the position of the lowest value with matching critera. what am i doing wrong??
 
Upvote 0
Are the values unique? If so, how about?:

Book4
ABCDEFG
1Criteria 1Cirteria 2Value to returnFiltered by criteria onlythird smallestIndex or postion
2a1101011011
3a12020
4a230110
5a240120
6a250
7b160
8b170
9b280
10b290
11b2100
12a1110
13a1120
14a2130
15a2140
16a2150
17b1160
18b1170
19b2180
20b2190
21b2200
22
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=FILTER(C2:C21,(A2:A21="a")*(B2:B21=1))
F2F2=SMALL(FILTER(C2:C21,(A2:A21="a")*(B2:B21=1)), 3)
G2G2=MATCH(SMALL(FILTER(C2:C21,(A2:A21="a")*(B2:B21=1)), 3), C2:C21, 0)
Dynamic array formulas.
Really appreciate the effort to try and recreate my issue, sincere thanks.

I have put together a quick recreation of the problem now which hopefully demonstrates it more effectively than my incoherent rambling and unoptimised formulas!
 
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