Articles on: Tutorials

How to compute totals in Excel / Spreadsheets when Carbone injects new lines?

Problem



Most spreadsheet reports need totals at the bottom of the table.

But the bottom of the table is dynamically pushed down by Carbone when the data is inserted.

So you cannot use a formula =SUM(B1:B2) because B2 is dynamic. It can be B88 or B351 when Carbone has inserted the data.

Here are two solutions:

Use a dynamic Excel formula



Place this formula in any summary cell in your template worksheet, and it will produce the sum of all the numbers in the column above that cell:

=SUM(INDIRECT(ADDRESS(1;COLUMN())&":"&ADDRESS(ROW()-1;COLUMN())))

Make sure that your Carbone tags end with the formatN formatter to convert numeric values to Excel numbers. Otherwise, the formula will not work.

Use Carbone aggregators



Carbone can compute the total itself

{d.lines[].price:aggSum:formatN}

Updated on: 09/29/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!