You'd have to reset sum to zero before every calculation. As a more complete example you could put it in a function so you could calculate xp() from anywhere with for example function.call("xp", 20).
global number sum=0
On function "xp"
---- set sum to 0
-------- for "n" from 1 to Function.param(0)-1
------------ add 75*2^(loopindex/7) to sum
-------- every tick
------------- function: set return to sum