i i understand correctly
this script will calculate the accumulative sum for each year
(ooxml, embedded labels, table is Sheet1);
if([Year]=previous([Year]),RangeSum(peek('ValueYTD'),[Value]) ,[Value]) as ValueYTD
Order By [Year],[FMonth];
drop Table DataTemp;
The answer Liron gave you will do the trick.
But just to elaborate on why your script didn't work:
You populate the variables with only the first row - min/max of first year.
You didn't include a 'next i' code to continue the loop.
That's why you end up with only two rows of value of the first month for both the years.
Hope it helps,