AnsweredAssumed Answered

Python Accumulate Values

Question asked by henry296 on Sep 15, 2015
Latest reply on Sep 23, 2015 by Dan_Patterson

In another post, I found this python script that creates a running total.  I was able to modify it to do a running product, but I need to have the running product reset when the value of another field changes.

 

How might I modify this code to do that?

 

  • Calculate the accumulative value of a numeric field.
  • Expression:
  • accumulate(!FieldA!)
  • Expression Type:
  • PYTHON_9.3
  • Code Block:
  • total = 0
  • def accumulate(increment):
  • global total
  • if total:
  •   total *= increment
  • else:
  •   total = increment
  • return total

 

My data is similar to this

95

IDValue
1
19
2
25

 

The answer would be 1 = 81 and 2 = 25 in the 2nd row of each ID.

Outcomes