ReoGrid ReoGrid Web

Running Total Column

A running total (cumulative sum) is a classic spreadsheet pattern: each row’s total = previous row’s total + current row’s value. In ReoGrid it’s a one-line formula per row.

Pro only. SUM is a Pro function. In Lite, replace with =B2 / =C1+B2 (arithmetic only).

Full example

import { createReogrid } from '@reogrid/pro';

const { worksheet } = createReogrid('#grid');

// Headers
worksheet.cell('A1').setValue('Date').setStyle({ bold: true });
worksheet.cell('B1').setValue('Amount').setStyle({ bold: true });
worksheet.cell('C1').setValue('Running Total').setStyle({ bold: true });

const data = [
  { date: '2026-04-01', amount:  120 },
  { date: '2026-04-02', amount:   85 },
  { date: '2026-04-03', amount:  210 },
  { date: '2026-04-04', amount: -40  },
  { date: '2026-04-05', amount:  175 },
];

data.forEach((d, i) => {
  const row = i + 2;  // A1 is header, so data starts at row 2
  worksheet.cell(`A${row}`).setValue(d.date);
  worksheet.cell(`B${row}`).setValue(d.amount);

  // The running-total formula: SUM from the first data row ($B$2) to the current row.
  worksheet.setCellInput(row - 1, 2, `=SUM($B$2:B${row})`);
});

worksheet.range(`B2:C${data.length + 1}`).setFormat('$#,##0.00');
worksheet.column(2).width = 140;

Why the $ matters

In =SUM($B$2:B3):

  • $B$2 is an absolute reference — it never shifts.
  • B3 is relative — it shifts with the row.

When the formula engine copies or updates references (e.g. when you insert a row), the anchor stays pinned and the range always grows from row 2 to the current row.

Reset per group

If your data has groups (e.g. monthly totals that reset each month), change the anchor to point at the first row of each group. The simpler alternative is the “previous total + current value” pattern:

// C2: =B2
worksheet.setCellInput(1, 2, '=B2');

// C3..Cn: =C(n-1)+B(n)
for (let row = 3; row <= data.length + 1; row++) {
  worksheet.setCellInput(row - 1, 2, `=C${row - 1}+B${row}`);
}

This pattern works in both Lite and Pro since it uses only arithmetic.

See also

Stay Updated

Be first to know — get updates as they ship

Get notified of new releases, features, and announcements.
No spam — just updates that matter.