Help With Lat Long Formulas

welshraz

New Member
Joined
Apr 29, 2016
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hello hello,

I have these different formulas which pull through a reference number based on the nearest coordinates:-

=IFERROR(LOOKUP(1,1/FREQUENCY(0,MMULT((CombinedNOI[Lat]:CombinedNOI[Long]-U13:V13)^2,{1;1})),CombinedNOI[ORREFERENCEID]),"")
=IF(U13="","",LOOKUP(1,1/FREQUENCY(0,SIN((RADIANS(CombinedNOI[Lat]-U13))/2)^2+SIN((RADIANS(CombinedNOI[Long]-V13))/2)^2*COS(RADIANS(CombinedNOI[Lat]))*COS(RADIANS(U13))),CombinedNOI[ORREFERENCEID]))
=IFERROR(INDEX(CombinedNOI[ORREFERENCEID],MATCH(MIN(SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2)),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),0),1),"")

They work really well, but is there any way of amending them so that they pull through the second and third closest?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
  1. To get the second closest reference: =IFERROR(INDEX(CombinedNOI[ORREFERENCEID],MATCH(LARGE(IF((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2<>MIN((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2)),2),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),0),1),"")
  2. To get the third closest reference: =IFERROR(INDEX(CombinedNOI[ORREFERENCEID],MATCH(LARGE(IF((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2<>MIN((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2)),3),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),0),1),"")
 
Upvote 0
  1. To get the second closest reference: =IFERROR(INDEX(CombinedNOI[ORREFERENCEID],MATCH(LARGE(IF((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2<>MIN((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2)),2),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),0),1),"")
  2. To get the third closest reference: =IFERROR(INDEX(CombinedNOI[ORREFERENCEID],MATCH(LARGE(IF((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2<>MIN((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2)),3),SQRT((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2),0),1),"")
Hmmmm.....I have tested both of these, and whilst they do pull through a different reference as expected, it is not the second or third closest. In all tests the reference that they pulled through is at least 50km away, when in reality they should be within a 5km radius.
 
Upvote 0
=INDEX(CombinedNOI[ORREFERENCEID], MATCH(SMALL(IF((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2>0, (CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2), 2), (CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2, 0))

And here's an example for the third closest reference:

=INDEX(CombinedNOI[ORREFERENCEID], MATCH(SMALL(IF((CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2>0, (CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2), 3), (CombinedNOI[Lat]-U13)^2+(CombinedNOI[Long]-V13)^2, 0))
 
Upvote 0
@welshraz
I have removed the 'Mark as solution' tick from post #3 as your comments in that post do not provide a solution to the original question. This is to help future readers.
Note that it is not a 'Mark as solved' or 'I don't require further help' checkmark in our forum.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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