Select to view content in your preferred language

Calculate New Field using Total of Existing Field

834
4
01-14-2011 10:09 AM
RuthLasher
New Contributor
I have a large number of shapefiles with a "Pop" field representing population counts.  To each shapefile, I'd like to add and calculate a new field, "Pop_per", to represent each row's share of the total population (total population = sum of "Pop" values across all rows). To illustrate...

I have:

ID  Pop
0   15
1   52
2   23
3   46

I'm trying to get here:

ID  Pop Pop_per
0   15   .11
1   52   .38
2   23   .17
3   46   .34

I know how to do this manually in the Attribute Table, but am looking for a way in either Model Builder (preferable so I can insert it in an existing model) or as a script.  Each shapefile has a different number of features.  Any ideas?
0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
Ruth,

You don't say which version of ArcGIS you are using, you need to tell us so that people can help you. Tools and models are implemented very differently in the different versions.

Assuming ArcGIS 10 then you could do a summary statistic on your shapefile to get the column sum and do that into an In_Memory table. I think there is a tool called collect value so you can get the Sum value then finally do a calculate with an inline substitution, all this can be achieved in model builder, if you have version 10...

Duncan
0 Kudos
RuthLasher
New Contributor
Version 9.3, thanks
0 Kudos
DuncanHornby
MVP Notable Contributor
Ruth,

Here is a 9.3 model that does what you want. You may want to tweak it for your needs and to document it better.

Duncan
0 Kudos
RuthLasher
New Contributor
Thanks Duncan, This is exactly what I was looking for.
0 Kudos