Select to view content in your preferred language

How to populate a field for each record with the total sum of another field?

1731
8
Jump to solution
12-04-2020 12:36 PM
JenniferGoldman
Emerging Contributor

Hello,

 

I am attempting to create a field that shows the amount equal to the total of a specific attribute (as a reference denominator field) to calculate the percentage of the total of each record in a separate field  

 

I did attempt to summarize, but this only created a table with one field of the total. I see that I am supposed to join the data back in with the original data but how do I do this if there is only one field? Can you populate a whole column with one join?

I hope this makes sense and thank you to anyone who is able to help! 

 

help pic.png

 

-Jenny

0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Emeritus

A couple things to consider:

1. What Type of field is PRCNT?  I'd make a float.  My bet is you have as an integer, and that  type of field can't handle decimal places that you will have. 

2. I always use Python expressions so it would look like :

!TOTAL_PROJ! / 1813828471

That just gives you a rational number.  To get true percent:

(!TOTAL_PROJ! / 1813828471) * 100

That should just about do it....

View solution in original post

0 Kudos
8 Replies
JoeBorgione
MVP Emeritus

Maybe you don't need that Total_All field.  Is the data dynamic? If not you know the value of Total_All already, so you could just plug that value in field calculator for the PRCNT field.

If the data is dynamic it will get a little sticker but doable with a cursor or two in python.

 

That should just about do it....
0 Kudos
JenniferGoldman
Emerging Contributor

Yes! You're right. I ended up using the field calculator and just saying it was equal to that total amount (for the Total_ALL field). I didnt realize it would populate all records, so much easier than I originally thought. Unfortunately, now my calculation isnt working, so I think I'll end up doing the calculation in excel (which I was trying to avoid). Thank for you reply!

0 Kudos
JoeBorgione
MVP Emeritus

Friends don't let friends use Excel to do GIS work:  do you get an error now?  If so what is it? Can you share the the calculate expression you are using?

That should just about do it....
0 Kudos
JenniferGoldman
Emerging Contributor

I keep entering into my PRCNT field with the calculator:

PRCNT = [TOTAL_PROJ] / 1813828471

but it keeps giving me 0 (I tried playing around with the numeric display by adding decimal places, but still no go)

0 Kudos
JoeBorgione
MVP Emeritus

A couple things to consider:

1. What Type of field is PRCNT?  I'd make a float.  My bet is you have as an integer, and that  type of field can't handle decimal places that you will have. 

2. I always use Python expressions so it would look like :

!TOTAL_PROJ! / 1813828471

That just gives you a rational number.  To get true percent:

(!TOTAL_PROJ! / 1813828471) * 100

That should just about do it....
0 Kudos
JenniferGoldman
Emerging Contributor

Yes! That did it. I was using a long integer before and even caught on to what you were suggesting during my own troubleshooting (I started setting the precision to 100,000 as an experiment, but perhaps that was not even enough! Better to do a Float now when unsure I suppose). 

 

Thank you for your help, this will help my project tremendously. 

0 Kudos
JoeBorgione
MVP Emeritus

Long Ints or Short Ints won't do decimal places no matter what you set the precision to.  I use typically I use floats for decimal numbers but double works as well.

That should just about do it....
0 Kudos
JenniferGoldman
Emerging Contributor

Ahhhh, see I incorrectly assumed Double was used for calculating geometry and I had honestly never used Float before. It makes sense though, with an integer being an integer (like you said). 

0 Kudos