Create Territories

markoakes

Active Member
Joined
Jan 5, 2004
Messages
325
I have a list of several hundred customers with Latitude and Longitude for each. I need to create sales Territories that have an equal number of customers and are grouped geographically. Any suggestions on the best way to accomplish this using just Excel?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Upvote 0
I took the liberty of creating a sample matrix for you.

Copy E7 and I7 down. Copy B15 across and down.

ABCDEFGHI
6hmsLatitudehmsLongitude
7Calgary5124651.04611114324114.0567
8Edmonton53324353.545281132921113.4892
9Montreal4530645.501677334273.56722
10New York40424640.712787402174.00583
11Seattle47362247.606111221955122.3319
12Vancouver45381945.638611223941122.6614
13
14CalgaryEdmontonMontrealNew YorkSeattleVancouver
15Calgary028130193259711874
16Edmonton2810297332569081098
17Montreal30192973053436743760
18New York32593256534038663922
19Seattle711908367438660220
20Vancouver8741098376039222200

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

Worksheet Formulas
CellFormula
E7=B7+C7/60+D7/3600
I7=F7+G7/60+H7/3600
B15=ACOS(COS(RADIANS(90-INDEX($E$7:$E$12,MATCH($A15,$A$7:$A$12)))) *COS(RADIANS(90-INDEX($E$7:$E$12,MATCH(B$14,$A$7:$A$12)))) +SIN(RADIANS(90-INDEX($E$7:$E$12,MATCH($A15,$A$7:$A$12)))) *SIN(RADIANS(90-INDEX($E$7:$E$12,MATCH(B$14,$A$7:$A$12)))) *COS(RADIANS(INDEX($I$7:$I$12,MATCH($A15,$A$7:$A$12))-INDEX($I$7:$I$12,MATCH(B$14,$A$7:$A$12)))))*6371

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

<tbody>
</tbody>
 
Upvote 0
Thank you for your help so far. I understand how to create the matrix but I have not used the Solver add-in before. My matrix has about 10,000 accounts and I need to create 40 Territories with the tightest geography and about the same number of accounts. Any hints on how to do that with the Solver? Thanks again.
 
Last edited:
Upvote 0
Stay tuned while I think it through. This kind of multi-modal optimisation is vexing.
 
Upvote 0
I have made some headway. Forgive the massive amount of data here; I had to create enough data to properly conduct experiments. I made 12 locales and divided them into 3 regions. I see that you wish to divide your 10,000 locales into 40 regions. Notice that I put random numbers in the region field starting in B37.

Copy E7, I7, E41, F41 down. Copy B22 across and down. After that, we will invoke Solver.

ABCDEFGHIJKLM
6localehmsLatitudehmsLongitude
7Calgary5124651.046114324114.057
8Edmonton53324353.5451132921113.489
9Helena46354546.596112137112.027
10Salt Lake4045040.750111530111.883
11Montreal4530645.5027334273.567
12Ottawa4525045.4177541075.683
13New York40424640.7137402174.006
14Washington38541738.9057705977.016
15Seattle47362247.6061221955122.332
16Spokane47393247.6591172530117.425
17Vancouver4915049.25012360123.100
18Victoria48254348.4291232156123.366
19
20
21129668CalgaryEdmontonHelenaSalt LakeMontrealOttawaNew YorkWashingtonSeattleSpokaneVancouverVictoria
22Calgary028151711573019287632593168711449674729
23Edmonton281078014282973283832563194908711819894
24Helena51778006502941278530962957787425875875
25Salt Lake1157142865003124296031662965112888612901245
26Montreal301929732941312401655347863674331636863726
27Ottawa287628382785296016505407323524316435393578
28New York325932563096316653454003263866349939033931
29Washington316831942957296578673232603738337037913812
30Seattle711908787112836743524386637380368191119
31Spokane44971142588633163164349933703680454450
32Vancouver67481987512903686353939033791191454093
33Victoria72989487512453726357839313812119450930
34
35
36localeRegionRegions3
37Calgary1Locales12
38Edmonton3Locales per region4
39Helena2
40Salt Lake2regioncountdistances
41Montreal31415225
42Ottawa3244243
43New York13414020
44Washington1total:33489
45Seattle2
46Spokane2
47Vancouver3
48Victoria1

<tbody>
</tbody>
latlong2

Worksheet Formulas
CellFormula
E7=B7+C7/60+D7/3600
I7=F7+G7/60+H7/3600
A21=SUM(B22:M33)/2
E37=COUNTA(A37:A48)
E38=E37/E36
E41=COUNTIFS($B$37:$B$48,D41)
F44=SUM(F41:F43)

<tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
B22{=ACOS(COS(RADIANS(90-INDEX($E$7:$E$18,MATCH($A22,$A$7:$A$18,0)))) *COS(RADIANS(90-INDEX($E$7:$E$18,MATCH(B$21,$A$7:$A$18,0)))) +SIN(RADIANS(90-INDEX($E$7:$E$18,MATCH($A22,$A$7:$A$18,0)))) *SIN(RADIANS(90-INDEX($E$7:$E$18,MATCH(B$21,$A$7:$A$18,0)))) *COS(RADIANS(INDEX($I$7:$I$18,MATCH($A22,$A$7:$A$18,0))-INDEX($I$7:$I$18,MATCH(B$21,$A$7:$A$18,0)))))*6371}
F41{=SUM(($B$37:$B$48=D41)*TRANSPOSE($B$37:$B$48=D41)*$B$22:$M$33)/2}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

Now invoke Solver using the following settings.
Set Objective click on $F$44
Min
By changing cells $B$37:$B$48
Subject to constraints: create four of them them by choosing the Add button
$B$37:$B$48 <= $E$36
$B$37:$B$48 = integer
$B$37:$B$48 >= 1
$E$41:$E$43 = $E$38
remove checkmark from 'Make unconstrained'
Select solving method as Evolutionary
ignore the other settings for now - the defaults should be adequate
click on Solve.

Solver should now vibrate around until it comes up with a solution. The outcome which should appear will be one where our first four locales are assigned to one region (one of 1, 2, 3) the second four to another, and the final four to a third. I happen to know that this will be the proper answer. This process should minimize the total distances to one another across the regions. Which, I believe, was our objective.

Give it a try and let us know how it goes. I anticipate that 10,000 locales and 40 regions is going to be markedly slower than our 12&3 experiment, if it even works at all.
<strike></strike>

<tbody>
</tbody>
 
Last edited:
Upvote 0
Wow, that looks like you spent a lot of time on this. Thank you . I am away from my computer for the weekend but will test this on Monday.
 
Upvote 0

Forum statistics

Threads
1,215,481
Messages
6,125,057
Members
449,206
Latest member
Healthydogs

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