Totals & references
Sum blocks with subtotal and total, reference any line with R2.
A line that just says subtotal adds up the run of values directly above it. Blank lines and headings end a block, so each section of your document can have its own subtotal.
total
total sums every value line above it in the whole document, and it never double-counts other totals or subtotals. Both keywords work inside an assignment, and both keep units, so a block of dollars sums to dollars.
average, count, and inline stats
average and count work like subtotal on the block above: average keeps the unit, count just counts the value lines. Aggregates written one under the other share the same block, so total, then average, then count all describe the values above them. For a one-liner, write average of or median of with a list, and there is also midpoint of A and B, range of a list (max minus min), and min/max/std of a list.
The block rules, exactly
A subtotal block is broken by blank lines, text lines, and other totals or charts, so each section sums just its own run of values. Lines with errors, dates, or rate declarations are skipped but do not break the block, so one typo in a long budget does not zero your sum. Mixed lines follow one rule: summing upward from the total, plain numbers adopt the unit (2500, 800, $680 totals $3,980), compatible units and currencies convert, and the first line that does not fit ends the run instead of erroring. An empty block sums to 0.
Row references
R2 means the result of line 2, the number shown in the left gutter. The fastest way to write one is to click any result pill. References only point upward, and units come along, so a reference to a distance stays a distance.
prev, the line just above
prev is shorthand for the result of the nearest value line above, so you can keep a running calculation going without naming each step. It skips headings, blank lines, dates and charts to find the last real number, and units and currencies come along. Spanish is anterior, French is précédent.
References repair themselves
If you insert or delete lines above a reference, the reference renumbers automatically so it keeps pointing at the same content. The reference you are actively typing is never touched. And if you name a variable r2, your variable wins over the reference syntax.