Let's have a look to the following piece of script.
If we run it and if we create a table where the expression is the dollar expansion of the variable vSum, that is $(vSum), we don get the expected result. We get the result below instead.
We expected the result below.
When the equals sign is included in the definition of the variable, the value of the variable in the chart is calculated before the dollar expansion takes part and as a consequence of this, the result is not taking into account the chart's dimension and instead it is equivalent to sum(TOTAL Exp).
In order to get the expected result you need to take away the equals sign from the definition of the variable.
Modifying the script so it looks like the one below produces the expected result.