Sorry for replying to my own post. I received an email for a reply but the thread still hasn't been updated.

Thanks for pointing out what the issue is, I understand now. The expression for the image is actually the tricky part, the expression I gave only works for the first record. What you need is a running total that you can subtract from "PAGE_NR() - 1".

There are two solutions that come to mind (without altering the data):

1. Use a custom SQL query

This only works if your data has an order column. If it has an ID field that starts at 1 and increments every record you can do:

Database > Select Table > Custom (double-click)
Code:
SELECT (SELECT SUM(Pages) FROM [Test.csv] as A WHERE A.ID < B.ID) AS RunningTotal, * FROM [Test.csv] AS B


Note that the filename of the data file needs to be hardcoded (without a path). The query above assumes the filename is Test.csv.

2. Create a custom macro

Create a folder called "Macro" in the PSM installation folder (this requires admin rights) with a file (any name) with extension ".js" and the following content:

Code:
function psmGetFunctionDescriptor(index) {
    return index == 0 ? "NUMBER NUMBER RUNNING_TOTAL(NUMBER{Record},NUMBER{Pages})" : "";
}

var total = 0;

function psmRUNNING_TOTAL(record, pages) {
	if (record == 1) total = 0;
	var previous = total;
	total += pages;
	return previous;
}


You should then have access to a RUNNING_TOTAL function that you can call passing RECORD_NR() and VAL([Pages]). This only works if you are creating output starting with record 1, since that is the "reset" trigger of the running total.