I don't think I have any real insights that are going to actually help you. I think you may need to question the Xero gurus on whatever web forum they congregate on.
I can say that the statement does NOT tell Xero how many invoice lines there are. Your document is a mail merge document that is running a dynamic query on the Xero database and the number of invoice lines depends on how many records in that database match the query parameters.
Basically the mail merge works using a SQL query to gather records out of Xero. Now it is possible to construct a SQL query to return a running total (
see this example) so it is conceptually possible to create the necessary field as part of the query you are using but I have no way of testing that without the software. I assume the SQL query is built on the fly by the user clicking a button in Xero so it would need to be sorted there.
If you could run a macro on the file AFTER the rest of the table is produced it would be relatively simple to populate the Cumulative Total column but this is likely not an option you (or your clients) would entertain.
If we were to say that the Opening Balance is always zero then in my
non-accounting mind I would assume that Balance and Cumulative Balance would be the same thing.
However you say that «Balance» shows the balance remaining on that invoice. Are you saying this is the same value on every row (ie equal to «TotalDueAmount») or is it the difference between «Amount» and «PaidAmount» just on that row of the table?