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.
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
| Keyword | Result |
|---|---|
sum or total | Sum of the block |
subtotal | Sum of the block (handy before a blank line) |
average or avg | Arithmetic mean |
median | Middle value |
min / max | Smallest / largest value |
count | How many values |
grandtotal | Sum of all subtotals above |
Results appear next to each line in Zlv Desktop. Download it free.
Results appear next to each line in Zlv Desktop. Download it free.
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.
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.
Evaluating…
Function forms
max and min accept a list of values in every engine. The desktop engine also has sum(...), avg(...), median(...) and count(...).
Evaluating…
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.
Related pages
- Comments, labels and line references
- Matrices and linear algebra, where
sum(A)andavg(A)work on matrices.