I need to automatically calculate a field based on values from previous rows

8628
28
04-13-2016 01:59 AM
OLANIYANOLAKUNLE
Occasional Contributor II
  • I need to automatically calculate a field based on values from previous rows?I need to automatically calculate a field based on values from previous rows such that once the total of all the previous rows is greater than 450 and less than 500, the next row starts counting from 0 or the balance of what made the previous row greater than 500. The script below just calculates the sum of the cities point that falls within the county, I want something that would make the value of a row (i.e. row2) the addition of the value of row1 + value of row2 and so on till when it gets to 500, where it starts from 1 again. Kindly help me please.

0 Kudos
28 Replies
WesMiller
Regular Contributor III

Could you expand on your example so we may get a better understanding of what you are trying to do?

0 Kudos
DanPatterson_Retired
MVP Emeritus

previous link and advice can be found here if anyone is looking for background I need to automatically calculate a field based on values from previous rows

0 Kudos
AdrianWelsh
MVP Honored Contributor

It looks like clarity is needed on both of these threads. Is there a way to combine both of them in order to consolidate and alleviate confusion?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Waiting for clarification ... but that is not in our hands

0 Kudos
OLANIYANOLAKUNLE
Occasional Contributor II

Thanks for your reponse(s), what i want to achieve is to get the sum total of values from a field called population, but i really don't want the final sum, what i need is to get the sum as you loop through the rows (that's the population value)  i.e if

row 1 = 23 (row 1 would be 23 as there's no other row/record before row1)

row 2 = 30 (row 2 would be 30 + the value in row 1)

row 3 = 22 (row 3 would be 22 + the value in row 2), till you reach the last row.

I also want to add a constraint whereby if the sum of the population values in the rows becomes 500, the next row's value would start from zero or the difference that makes the 500 from the previous row. Thanks

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The first part of your request, if I understand it, seems straightforward enough, but I don't get the threshold condition.  You state if the population values in the rows becomes 500 (do you mean exactly 500?), then the next row's value is either zero or some difference.  Well, which is it, zero or the difference?  Can you present an example like the one above but showing the 500 threshold value in action?

0 Kudos
OLANIYANOLAKUNLE
Occasional Contributor II

Thanks for your views, the threshold is for any population value that falls between 450 - 500, now if the population for a particular row adds up to 503 - the population value of the next row would be (503 - 500) + the absolute population value of that row, likewise if the population for a particular row adds up to 498, then the population value of the next row would automatically start from  the absolute population value of that row as nothing would be added to the absolute population value for that particular row.

0 Kudos
DanPatterson_Retired
MVP Emeritus

the quickest way would be to use a spreadsheet since you can copy the formula as you need it.  Since you don't seem to be doing thousands or rows nor have you indicated that this would be a daily calculation, it may be faster in the long run to set up a template spreadsheet, then bring it into Arc* for further work.

0 Kudos
AdrianWelsh
MVP Honored Contributor

It's such a bummer when the quickest way is to not use Python, but easier is easier... I agree with Dan.

0 Kudos