=SMALL function not working due to "ties"

ARehn

New Member
Joined
Apr 12, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am working on a tool to determine the 5 closest locations to a zip code. The user will enter a zip code on the "Main Page" in C5 and the 5 closest locations on page 2 will populate in column F 4:8. I am using the following to determine the distance between zip codes:

=6371*2*ASIN(SQRT(SIN((RADIANS('Main Page'!$C$8)-RADIANS(Table2[@Column4]))/2)^2+COS(RADIANS('Main Page'!$C$8))*COS(RADIANS(Table2[@Column4]))*SIN((RADIANS(Table2[@Column3])-RADIANS('Main Page'!$C$7))/2)^2))

I then use math to convert to miles, because, well, the USA. Using

=SMALL(Sheet2!P:P,{1;2;3;4;5})

to get my five closest locations works great, most of the time. It is when I have a zip code with multiple locations that the results are skewed. Due the "tie" I get results that are duplicated and others are omitted. What can I use in place of =SMALL to give me the results when a specific zip code has "ties"

The other problem I am running into is that C5 on the main page is a Geography Data Type. Excel does not like East coast zip codes that begin with 0. If I use a zip code for Trenton, NJ, 08601, it does not return a result because the beginning 0 gets dropped. If I use '08601, then the Geography Data Type gets erased. Any ways around this?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I’m not quite following the problem. It sounds as if every “location” that shares a common ZIP code uses identical latitude and longitude coordinates? Are you using a central single-point location to represent all addresses or locations within a ZIP code? If you want the five smallest distances based on the lat-long coordinates for each location, then you’ll need to use the lat-long coordinates for the locations, not a much-less granular lat-long applied to all locations within a ZIP code. On the other hand, if you want to use a less granular single lat-long for all locations within a ZIP code, then it would make sense to filter the list of ZIPs to ensure that only unique ZIP codes are considered…and there would be no duplicates.

Would you clarify these points further? I don’t know if you’ve seen a similar thread where the smallest distances were sought based on address-specific lat-longs:

It is conceivable that two locations might produce the same distances, perhaps even locations in different ZIP codes or different states. I’m assuming that in the case of those “ties”, you would still want them reported back in the “shortest five” list?
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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