So far so good, the problem is to calculate the average existence for which I must sum the final existence of every day, from day 1 to selected day (in this case 3) and divide it by the number of the selected day. That is the sum of the above expression for each day from 1 to 3 divided by 3. Something like this:
(
Sum({$<Day = {1}>} ini_inv + ent_inv - sal_inv) + // Final existence of day 1 = 'ini_inv' of day 2.