Sumif within distance from a latitude and longitude pairing

Mdeco

New Member
Joined
Nov 19, 2018
Messages
3
Hi there,

I have two lists of coordinates (i.e. latitudes and longitudes), the second of which has a "sales count" associated with it. I want to get a sum of the "sales counts" occurring within x miles of the first list of coordinates. How would you suggest I do this?

See below:

1ABCDEFG
2
3Radius100
4
5LatLongSum Column G if within range B3Lat 2Long 2Sales
642.125793-72.645334?41.377698-104.6603531
742.184835-71.947184?43.950896-110.5531811
842.10273-72.080996?43.50537-110.7865272
942.446396-71.459405?43.50537-110.7865273
1042.504844-71.201539?43.452793-110.7392661
1142.472112-70.997794?43.452793-110.7392661
1242.536996-70.973646?43.452793-110.7392661
1342.347207-71.086095?44.653104-107.0247131
1442.202216-71.005192?43.044268-111.0085171
1542.357564-71.211649?42.785695-110.1865991
1642.379146-71.184299?43.482361-110.8397821
1741.829813-70.138834?43.482361-110.8397822

<tbody>
</tbody>

<tbody>
</tbody>

The formula for the distance between lat/ long is =ACOS(COS(RADIANS(90-Lat1)) *COS(Radians(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(Radians(Long1-Long2))) *6371
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
typically the first set of co-ords is over 2500 miles from the second set, thus 100 miles radius won't yield any result unless I interpreted your question incorrectly
 
Upvote 0
this will sum up the sales if set 2 co-ords is within 3175 miles (B3) from set 1


Book1
ABCDEFG
1
2
3Radius3175
4
5LatLongSum Column G if within range B3Lat 2Long 2Sales
642.12579-72.6453162641.50641.3777-104.661
742.18484-71.9472163113.55743.9509-110.5531
842.10273-72.081163132.92643.50537-110.7872
942.4464-71.4594123171.61843.50537-110.7873
1042.50484-71.201543187.69643.45279-110.7391
1142.47211-70.997823204.76543.45279-110.7391
1242.537-70.973623204.72743.45279-110.7391
1342.34721-71.086132886.47644.6531-107.0251
1442.20222-71.005223243.09343.04427-111.0091
1542.35756-71.211643163.09142.7857-110.1871
1642.37915-71.184343200.11143.48236-110.841
1741.82981-70.138822641.50643.48236-110.842
Sheet1
Cell Formulas
RangeFormula
C6=SUMPRODUCT(--(ACOS(COS(RADIANS(90-$A6)) *COS(RADIANS(90-$E$6:$E$17)) +SIN(RADIANS(90-$A6)) *SIN(RADIANS(90-$E$6:$E$17)) *COS(RADIANS($B6-$F$6:$F$17))) *6371<$B$3),$G$6:$G$17)
D6=ACOS(COS(RADIANS(90-A6)) *COS(RADIANS(90-E6)) +SIN(RADIANS(90-A6)) *SIN(RADIANS(90-E6)) *COS(RADIANS(B6-F6))) *6371
 
Upvote 0
Thanks, AlanY! That's very helpful.

For my edification, can I ask why you place two hyphens after the opening of the first set of brackets? SUMPRODUCT(--


this will sum up the sales if set 2 co-ords is within 3175 miles (B3) from set 1

ABCDEFG
1
2
3Radius3175
4
5LatLongSum Column G if within range B3Lat 2Long 2Sales
642.12579-72.6453162641.50641.3777-104.661
742.18484-71.9472163113.55743.9509-110.5531
842.10273-72.081163132.92643.50537-110.7872
942.4464-71.4594123171.61843.50537-110.7873
1042.50484-71.201543187.69643.45279-110.7391
1142.47211-70.997823204.76543.45279-110.7391
1242.537-70.973623204.72743.45279-110.7391
1342.34721-71.086132886.47644.6531-107.0251
1442.20222-71.005223243.09343.04427-111.0091
1542.35756-71.211643163.09142.7857-110.1871
1642.37915-71.184343200.11143.48236-110.841
1741.82981-70.138822641.50643.48236-110.842

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C6=SUMPRODUCT(--(ACOS(COS(RADIANS(90-$A6)) *COS(RADIANS(90-$E$6:$E$17)) +SIN(RADIANS(90-$A6)) *SIN(RADIANS(90-$E$6:$E$17)) *COS(RADIANS($B6-$F$6:$F$17))) *6371<$B$3),$G$6:$G$17)
D6=ACOS(COS(RADIANS(90-A6)) *COS(RADIANS(90-E6)) +SIN(RADIANS(90-A6)) *SIN(RADIANS(90-E6)) *COS(RADIANS(B6-F6))) *6371

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
the first part of the formula compare the distance between the 2 sets of co-ords with the distance in B3 that yields an array of {ture, false, ture,...etc).
the -- is to convert that array to {1, 0, 1,...etc} in order for it to multiple the array in Col G for the summation
 
Upvote 0
the first part of the formula compare the distance between the 2 sets of co-ords with the distance in B3 that yields an array of {ture, false, ture,...etc).
the -- is to convert that array to {1, 0, 1,...etc} in order for it to multiple the array in Col G for the summation

That's helpful, thank you!
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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