Bank statement with page subtotals

Account transactions in a PDF, with a running balance

Generate bank statements from your banking software

Banks, credit unions and fintech platforms send a periodic statement for every checking account. In the US, Regulation E requires one for each monthly cycle with an electronic transfer, and at least one per quarter otherwise. The core banking system exports the account and its transactions as JSON, and the Carbone API returns the statement as a PDF, ready to print, to mail in a window envelope or to publish in online banking. In this example, Alderway Bank sends the October statement of an interest checking account: 54 transactions on 3 pages, with a page total and a balance carried forward at the bottom of each page. The bank, the customer and the merchants are fictional, and every page is marked as a specimen.

In this example, you will:

  • Compute the running balance of each transaction with :cumSum and :set
  • Group the transactions by page, with fewer rows on page 1, below the account summary
  • Print the debit and credit totals of each page
  • Print the balance brought forward and carried forward on each page
  • Remove the page break after the last page
  • Summarize the account with aggregators and array filters

The disclosures of a US bank statement

The layout follows the periodic statement disclosures of Regulation E (electronic fund transfers) and Regulation DD (Truth in Savings).

Disclosure Rule In the template
Account number, opening and closing balances Reg E 1005.9(b) Account details and account summary, page 1
Amount, posting date, type and payee or terminal location of each transfer Reg E 1005.9(b)(1) One row per transaction
Fees charged during the period, by type Reg E 1005.9(b)(3), Reg DD 1030.6 Fee rows, and the fee total of the summary
Address and telephone number, after "Direct inquiries to" Reg E 1005.9(b)(5) Below the account summary
Annual percentage yield earned, interest earned, statement period Reg DD 1030.6(a) Interest box, page 1
Total overdraft and returned item fees, for the period and the year Reg DD 1030.11 Fee summary, last page
Error resolution notice Reg E 1005.8(b), model form A-3(b) Last page

The account number is masked in this specimen: print the full number, or the truncation your compliance team approves.

How to paginate transactions with page subtotals

Follow these steps to display a fixed number of transactions per page, with a total and a balance at the bottom of each page.

  • Open the File menu, select Page Setup and choose the US Letter paper size.
  • In the header options, tick Different First Page. Page 1 shows the bank logo, its address and its customer service number. The next pages show a compact header with the customer, the account and the period: {d.customer.name}, {d.account.product} •••• {d.account.last4} and {d.statement.periodStart:formatD('MMM D')} to {d.statement.periodEnd:formatD('MMM D, YYYY')}.
  • The footer repeats the bank address, the statement number and the page number as "Page X of Y".

2. Group the Transactions by Page

The JSON data contains the openingBalance of the account and a transactions array with the date, type, description, reference, category and amount of each transaction. A debit has a negative amount. Four tags in the Transaction detail heading prepare the data. They print nothing.

{d.transactions[].amount:cumSum:add(d.openingBalance):set(.balance)}
{d.transactions[]:cumCount():add(17):div(32):ceil:set(.page)}
{d.transactions[]:set(c.pages[id=.page].rows[])}
{d.transactions[].page:aggMax:set(c.pageCount)}
  • The first tag stores the running balance in each transaction: :cumSum adds up the amounts, :add adds the opening balance, and :set(.balance) writes the result in a new balance field.
  • The second tag calculates the page number. A page holds 32 transactions, but page 1 holds only 15, below the account summary. :cumCount numbers the transactions, :add(17) adds the 17 rows that page 1 lacks, then :div and :ceil give the page. Transactions 1 to 15 land on page 1, 16 to 47 on page 2.
  • The third tag groups the transactions by page in a new pages array of the complement object c.
  • The last tag stores the number of pages in c.pageCount with :aggMax, to recognize the last page.

Here is the complement object after these tags:

{
  "pages": [
    { "id": 1,
      "rows": [
        { "date": "2026-10-01",
          "type": "ACH debit",
          "amount": -2148.36,
          "balance": 6088.12,
          "page": 1 },
        {...}
      ]
    },
    { "id": 2, "rows": [...] },
    { "id": 3, "rows": [...] }
  ],
  "pageCount": 3
}

3. Repeat a Page for Each Group

  • Write {c.pages[i]} in the first header cell of the transaction table, and {c.pages[i+1]} in the paragraph after the page break. Carbone repeats the table and the page break for each page.
  • Inside the table, a row loop prints the transactions of the page:
| {c.pages[i].rows[i].date:formatD('MM/DD')} | {c.pages[i].rows[i].type} {c.pages[i].rows[i].description} | {c.pages[i].rows[i].reference} | {c.pages[i].rows[i].amount:ifGTE(0):show():abs:formatN(2)} | {c.pages[i].rows[i].amount:ifLTE(0):show():formatN(2)} | {c.pages[i].rows[i].balance:formatN(2)} |
| {c.pages[i].rows[i+1]}                     |                                                           |                                |                                                            |                                                       |                                         |
  • In the Debits column, :ifGTE(0):show() hides the credits and :abs removes the minus sign. In the Credits column, :ifLTE(0):show() hides the debits. :formatN(2) prints the amounts with two decimals.
  • Give the transaction rows a height of at least 17 pt and keep each description on one line: the 32 rows then always fit on one page.

4. Calculate the Page Subtotals

In the Total this page row, array filters keep the debits or the credits of the current page, and :aggSum adds them up:

  • Debits: {c.pages[i].rows[amount<0].amount:aggSum:abs:formatN(2)}
  • Credits: {c.pages[i].rows[amount>0].amount:aggSum:formatN(2)}

5. Display the Running Balance

Two tinted rows frame the transactions of each page.

  • The top row shows the balance before the first transaction of the page: {c.pages[i].rows[0].balance:sub(.amount):formatC}. rows[0] is the first transaction of the page, and :sub(.amount) subtracts its amount from its balance. :formatC prints the amount in US dollars.
  • The bottom row shows the balance after the last transaction: {c.pages[i].rows[].amount:aggSum:cumSum:add(d.openingBalance):formatC}. :aggSum calculates the net amount of the current page, :cumSum adds the net amounts of the previous pages, and :add(d.openingBalance) adds the opening balance.
  • The labels change on the first and the last page with :show and :elseShow: {c.pages[i].id:ifEQ(1):show('Opening balance'):elseShow('Balance brought forward')} and {c.pages[i].id:ifEQ(c.pageCount):show('Closing balance'):elseShow('Balance carried forward')}.

6. Remove the Last Page Break

Each page ends with a page break. To avoid a blank page after the last one, add this tag in the paragraph of the page break:

{c.pages[i].id:ifEQ(c.pageCount):drop(p)}

c.pages[i].id is the page number. On the last page, it equals c.pageCount, and :drop(p) removes the paragraph with its page break. The fee summary and the error resolution notice follow the last table.

7. Summarize the Account

The account summary on page 1 adds up the transactions of each category with string filters and aggregators. For the credits:

  • Count: {d.transactions[category='credit'].amount:aggCount}
  • Total: {d.transactions[category='credit'].amount:aggSum:formatC}

The same tags with category='debit', 'fee' and 'interest' give the withdrawals, the fees and the interest paid, with :abs for the debits and the fees. The closing balance adds all the amounts to the opening balance:

{d.transactions[].amount:aggSum:add(d.openingBalance):formatC}

The core banking system sends the values that Carbone cannot derive from the transactions: the annual percentage yield earned, the average daily balance, the interest paid year to date and the overdraft fees of the year. :diffD counts the days of the period: {d.statement.periodStart:diffD(d.statement.periodEnd, 'days'):add(1)}.

Render with the "lang": "en-us" option: :formatC then prints US dollars, and :formatN uses the US separators.

Save the DOCX template, send the JSON of each account, and Carbone paginates the statement: the closing balance at the bottom of the last page matches the account summary.

Trusted by 800+ paid customers in 40+ countries

Finance
Healthcare
Insurance
Legal
Public
Retail
Energy
Software
Telecom
Dior
Thales
Younited
Danfoss
CMA CGM
Illumina
KparK
Scalingo
French Ministry of the Armed Forces
BMW
Telus
Bestseller
Flagship Biosciences
Insly
Ninox
Sodexo