Well, it worked for me when I created an example...
Created a bit more detailed example, with almost exactly the same loop that I showed in the image:
Download .capx
The reason why it didn't work for you is probably because you put the function call in the wrong location.
You need to execute the function each time when the amount of money changes.