Skip to content

Totals, sums and averages of a block

Add up lines in the Zlv desktop app with sum, total and subtotal, get average, median, min, max and count of a block, and combine blocks with grandtotal.

Aggregate keywords summarise the lines above them. They are part of the full Rust engine, so the examples on this page run in Zlv Desktop. For single lists of numbers in any engine, the functions max(...) and min(...) also work.

Blocks

A block is a run of lines with no blank line between them. Aggregates look at the numbers in the current block only, from the nearest blank line above down to the aggregate line. A comment line does not end a block; a blank line does.

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

Here sum is 70: the blank line separates 10 and 20 into their own block.

Keywords

KeywordResult
sum or totalSum of the block
subtotalSum of the block (handy before a blank line)
average or avgArithmetic mean
medianMiddle value
min / maxSmallest / largest value
countHow many values
grandtotalSum of all subtotals above
Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

Variables count too: a block of rent = 1200 and food = 400 followed by sum gives 1,600.

Subtotals and a grand total

Give each section its own subtotal, then add them all with grandtotal.

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

You can also store an aggregate in a variable, for example food_total = sum, and use it later.

Assigning to total

total = a + b creates a normal variable named total, and total * 2 uses that variable. However, a line containing only the word total is always the block sum keyword, not your variable. To avoid surprises, pick a more specific name such as order_total.

Live example
Edit the lines and press Run. Evaluated in your browser.

Evaluating…

Function forms

max and min accept a list of values in every engine. The desktop engine also has sum(...), avg(...), median(...) and count(...).

Live example
Edit the lines and press Run. Evaluated in your browser.

Evaluating…

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

Live sum and average

The desktop status bar can also show a running sum and average of every numeric result in the current sheet: open the ⋯ menu in the title bar and turn on Show engine details in status bar. That total includes intermediate and aggregate lines, so for a real total write a sum line.

All guides