Calculate Field Sum for Unique Set

423
4
Jump to solution
06-11-2013 01:03 PM
JohnDye
Occasional Contributor III
I have a table that I've modified coming out of the Network Analyst OD Cost Matrix (If you've read my other post on getting a result object to a GDB Table, I am currently getting this out of ArcMap as a workaround).

The table looks something like this like this, where the latter three fields are type 'Double'

OriginIDDestIDTotal_LengthMarketShareSum_MarketShare
112358924132611241.242455
112358924133611241.362644
112358924134611241.543264
112358924135611241.7254109
112358924132538561.362155
11235892413353856.241844
112358924134538561.533264
112358924135538561.2755109




I need to calculate the 'Sum_MarketShare' field to determine the Sum off all market share for each unique Block Group set.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor
If I understand correctly, you want to SUM the field MarketShare, grouped by some field (what is the Block Group?).

Two ideas:
1.) This is commonly done with the Summary Statistics tool (statistic=SUM, case_field=the Block Group field). Then, join (Add Join or Join Field) the result to the original table. Calculate the value into SUM_MarketShare. This can be done with Python or tools.
2.) Use cursors (SearchCursor and UpdateCursor) to sort, then loop through adding, then loop through updating, your data. This is Python only.

Not sure which takes longer to run. If you're doing this once, I'd use the tools. If not, spend time figuring out the cursors.

View solution in original post

0 Kudos
4 Replies
DarrenWiens2
MVP Honored Contributor
If I understand correctly, you want to SUM the field MarketShare, grouped by some field (what is the Block Group?).

Two ideas:
1.) This is commonly done with the Summary Statistics tool (statistic=SUM, case_field=the Block Group field). Then, join (Add Join or Join Field) the result to the original table. Calculate the value into SUM_MarketShare. This can be done with Python or tools.
2.) Use cursors (SearchCursor and UpdateCursor) to sort, then loop through adding, then loop through updating, your data. This is Python only.

Not sure which takes longer to run. If you're doing this once, I'd use the tools. If not, spend time figuring out the cursors.
0 Kudos
RichardFairhurst
MVP Honored Contributor
If I understand correctly, you want to SUM the field MarketShare, grouped by some field (what is the Block Group?).

Two ideas:
1.) This is commonly done with the Summary Statistics tool (statistic=SUM, case_field=the Block Group field). Then, join (Add Join or Join Field) the result to the original table. Calculate the value into SUM_MarketShare. This can be done with Python or tools.
2.) Use cursors (SearchCursor and UpdateCursor) to sort, then loop through adding, then loop through updating, your data. This is Python only.

Not sure which takes longer to run. If you're doing this once, I'd use the tools. If not, spend time figuring out the cursors.


Paired cursors in any form always take longer than Summary Statistics and Field Calculator in my experience.  Those two tools are far more optimized than the Python or ArcObjects cursors.
0 Kudos
JohnDye
Occasional Contributor III
This is commonly done with the Summary Statistics tool


Darren,
That's exactly what I was looking for! Thanks!!
0 Kudos
JohnDye
Occasional Contributor III
This is commonly done with the Summary Statistics tool


Darren,
That's exactly what I was looking for! 700+ tools makes it hard to find something when you don't know the name! Thanks!!
0 Kudos