simple problem - difficult solution(?): average distance between coordinates in same zone

6diegodiego9

Board Regular
Joined
Jan 9, 2018
Messages
80
Office Version
  1. 2016
Platform
  1. Windows
I have a list of coordinates (columns B and C) of agencies (rows) that are associated to a zone (column A).

I attached a screenshot of a reduced list as example.
In cell D2 of the example I put a formula that calculates the distance between coordinates in row 2 and row 3:
=6371*((2*ASIN(SQRT((SIN((RADIANS(B2)-RADIANS(B3))/2)^2)+COS(RADIANS(B2))*COS(RADIANS(B3))*(SIN((RADIANS(C2)-RADIANS(C3))/2)^2)))))

Untitled.png


I'm now asked to fill column E with the average distance between the coordinates of current row and the coordinates of each other row of the same zone (column A), on a real case file that has thousands of rows and 10s of zones...

How would you solve this problem?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi Diego,

How about simply using in cell E2 & below:
=AVERAGEIF(A:A,A2,D:D)

It will present the average distance for each zone.
 
Upvote 0
Could you take the average of the other A lat's and long's and then use your existing formula to calculate the distance between the current row and the averages? Would that work mathematically? The alternative is to calculate all of the distances and then average that.
 
Upvote 0
i was thinking something like this:


Sheet10

ABCDEFG
1zonelatlongdist (km)avg latavg longdist vs avg
2A45.4403310.997060.5545.4392611.004920.62
3A45.4376410.991110.7445.440611.00791.35
4C45.442710.997181.6945.4336611.043893.78
5A45.4408711.018733.8145.4389910.994091.93
6B45.4435210.969993.0245.4330910.987061.77
7B45.4187410.985814.8345.4454810.979153.02
8C45.4336611.043894.6045.442710.997183.78
9B45.4474310.98831 45.4311310.97791.99

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
D2=6371*((2*ASIN(SQRT((SIN((RADIANS(B2)-RADIANS(B3))/2)^2)+COS(RADIANS(B2))*COS(RADIANS(B3))*(SIN((RADIANS(C2)-RADIANS(C3))/2)^2)))))
E2=(SUMIF(A:A,A2,B:B)-B2)/(COUNTIF(A:A,A2)-1)
F2=(SUMIF(A:A,A2,C:C)-C2)/(COUNTIF(A:A,A2)-1)
G2=6371*((2*ASIN(SQRT((SIN((RADIANS(B2)-RADIANS(E2))/2)^2)+COS(RADIANS(B2))*COS(RADIANS(E2))*(SIN((RADIANS(C2)-RADIANS(F2))/2)^2)))))
D3=6371*((2*ASIN(SQRT((SIN((RADIANS(B3)-RADIANS(B4))/2)^2)+COS(RADIANS(B3))*COS(RADIANS(B4))*(SIN((RADIANS(C3)-RADIANS(C4))/2)^2)))))
E3=(SUMIF(A:A,A3,B:B)-B3)/(COUNTIF(A:A,A3)-1)
F3=(SUMIF(A:A,A3,C:C)-C3)/(COUNTIF(A:A,A3)-1)
G3=6371*((2*ASIN(SQRT((SIN((RADIANS(B3)-RADIANS(E3))/2)^2)+COS(RADIANS(B3))*COS(RADIANS(E3))*(SIN((RADIANS(C3)-RADIANS(F3))/2)^2)))))
D4=6371*((2*ASIN(SQRT((SIN((RADIANS(B4)-RADIANS(B5))/2)^2)+COS(RADIANS(B4))*COS(RADIANS(B5))*(SIN((RADIANS(C4)-RADIANS(C5))/2)^2)))))
E4=(SUMIF(A:A,A4,B:B)-B4)/(COUNTIF(A:A,A4)-1)
F4=(SUMIF(A:A,A4,C:C)-C4)/(COUNTIF(A:A,A4)-1)
G4=6371*((2*ASIN(SQRT((SIN((RADIANS(B4)-RADIANS(E4))/2)^2)+COS(RADIANS(B4))*COS(RADIANS(E4))*(SIN((RADIANS(C4)-RADIANS(F4))/2)^2)))))
D5=6371*((2*ASIN(SQRT((SIN((RADIANS(B5)-RADIANS(B6))/2)^2)+COS(RADIANS(B5))*COS(RADIANS(B6))*(SIN((RADIANS(C5)-RADIANS(C6))/2)^2)))))
E5=(SUMIF(A:A,A5,B:B)-B5)/(COUNTIF(A:A,A5)-1)
F5=(SUMIF(A:A,A5,C:C)-C5)/(COUNTIF(A:A,A5)-1)
G5=6371*((2*ASIN(SQRT((SIN((RADIANS(B5)-RADIANS(E5))/2)^2)+COS(RADIANS(B5))*COS(RADIANS(E5))*(SIN((RADIANS(C5)-RADIANS(F5))/2)^2)))))
D6=6371*((2*ASIN(SQRT((SIN((RADIANS(B6)-RADIANS(B7))/2)^2)+COS(RADIANS(B6))*COS(RADIANS(B7))*(SIN((RADIANS(C6)-RADIANS(C7))/2)^2)))))
E6=(SUMIF(A:A,A6,B:B)-B6)/(COUNTIF(A:A,A6)-1)
F6=(SUMIF(A:A,A6,C:C)-C6)/(COUNTIF(A:A,A6)-1)
G6=6371*((2*ASIN(SQRT((SIN((RADIANS(B6)-RADIANS(E6))/2)^2)+COS(RADIANS(B6))*COS(RADIANS(E6))*(SIN((RADIANS(C6)-RADIANS(F6))/2)^2)))))
D7=6371*((2*ASIN(SQRT((SIN((RADIANS(B7)-RADIANS(B8))/2)^2)+COS(RADIANS(B7))*COS(RADIANS(B8))*(SIN((RADIANS(C7)-RADIANS(C8))/2)^2)))))
E7=(SUMIF(A:A,A7,B:B)-B7)/(COUNTIF(A:A,A7)-1)
F7=(SUMIF(A:A,A7,C:C)-C7)/(COUNTIF(A:A,A7)-1)
G7=6371*((2*ASIN(SQRT((SIN((RADIANS(B7)-RADIANS(E7))/2)^2)+COS(RADIANS(B7))*COS(RADIANS(E7))*(SIN((RADIANS(C7)-RADIANS(F7))/2)^2)))))
D8=6371*((2*ASIN(SQRT((SIN((RADIANS(B8)-RADIANS(B9))/2)^2)+COS(RADIANS(B8))*COS(RADIANS(B9))*(SIN((RADIANS(C8)-RADIANS(C9))/2)^2)))))
E8=(SUMIF(A:A,A8,B:B)-B8)/(COUNTIF(A:A,A8)-1)
F8=(SUMIF(A:A,A8,C:C)-C8)/(COUNTIF(A:A,A8)-1)
G8=6371*((2*ASIN(SQRT((SIN((RADIANS(B8)-RADIANS(E8))/2)^2)+COS(RADIANS(B8))*COS(RADIANS(E8))*(SIN((RADIANS(C8)-RADIANS(F8))/2)^2)))))
E9=(SUMIF(A:A,A9,B:B)-B9)/(COUNTIF(A:A,A9)-1)
F9=(SUMIF(A:A,A9,C:C)-C9)/(COUNTIF(A:A,A9)-1)
G9=6371*((2*ASIN(SQRT((SIN((RADIANS(B9)-RADIANS(E9))/2)^2)+COS(RADIANS(B9))*COS(RADIANS(E9))*(SIN((RADIANS(C9)-RADIANS(F9))/2)^2)))))

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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