WebGen Linux Manual

Sheets — a budget, step by step

Build a monthly budget that adds up your income, takes off your expenses, and splits what is left between two savings accounts — where one number decides how the split falls. By the end you will have used every kind of reference Sheets has, and know how to see what it actually calculated when something looks wrong.

Open Sheets from Applications › Documents. Everything below is typed into one sheet; the finished file is at /usr/share/webgen-sheets/examples/monthly-budget.wgsheet if you would rather read the answer first.

1 · The idea in one paragraph

A sheet is a grid, and on the grid sit panels — separate blocks of columns, each with its own headings and its own calculations. A panel is what other spreadsheets call “a table”, except a sheet may hold as many as you like, side by side. A formula belongs to a column, not to a cell: write it once at the top and every row of that column runs it. That is why the formulas read like English rather than like =D4*$B$1.

$nameAnother column in this panel, on this row. Named after its heading: a column headed Pay Rate is $pay_rate.
$$nameOne fixed cell, wherever it sits. This is how a rate you type once reaches every formula that needs it.
$name[panel]The same column in another panel. This is how the savings split reads the surplus.
A1, SUM(B8:B11)Ordinary cell addresses and ranges, when you want to point at a region rather than name it.

2 · The rate that controls everything

Start at the top of the empty sheet. In A3 type Emergency share, and in B3 type 0.6000. That is the number the whole budget turns on: sixty per cent of whatever is left over goes to the emergency fund.

Now make B3 a shared rate so formulas can call it by name. A shared rate is just a cell you have given a name to — it is still an ordinary cell you can type in.

$$emergency_share   →  B3
Why a named cell instead of typing 0.6 into the formulas? Because you will change it. A rate written into four formulas is a rate you will change in three of them and spend an afternoon wondering why the totals disagree.

3 · Income

Add a panel (☰ › PanelsAdd a panel…) called Income, at column 0 row 6, with headings Source, Amount and 4 rows. Type your income in:

Source        Amount
Salary          4200
Freelance        650
Interest          35

Click the Amount heading. In the dialog set Totals row to SUM($amount), and under Appearance set the number format to Money. The column now reads $4,200.00 and a total of $4,885.00 appears under it.

The format is applied to the stored value, not just to the screen, so it travels with the sheet into CSV and into the Word export. And $4,885.00 still reads back as the number 4885 when the next formula uses it.

4 · Expenses

Another panel, Expenses, at column 4 row 6 — beside the income panel, not below it — with headings Item, Cost and 6 rows:

Item               Cost
Rent               1450
Groceries           620
Utilities           240
Transport           180
Insurance           155
Everything else     400

Give Cost the same treatment: SUM($cost) as its total, Money as its format. That comes to $3,045.00.

Sheets will refuse to put a panel on top of another one, and say which one it hit. A panel that quietly overwrote its neighbour would corrupt the numbers with no error at all, and you would have no way afterwards to tell whose was whose.

5 · What is left over

A third panel, Surplus, at column 0 row 15, with 1 row and three columns: Income, Expenses, Surplus. Click each heading in turn and give it a formula:

$income     =  SUM(B8:B11)
$expenses   =  SUM(F8:F13)
$surplus    =  $income - $expenses

The first two use cell ranges, because they reach into another panel's cells: B8:B11 is the income amounts, F8:F13 the costs. The third uses $income and $expenses — other columns of this panel, on this row. Set all three to Money and you have $4,885.00 − $3,045.00 = $1,840.00.

Column letters and row numbers run along the edges of the sheet, so you can read an address off the screen. The formula bar shows the address of whatever cell you are in.

6 · Splitting the surplus

The last panel, Savings split, at column 0 row 20, 1 row, four columns:

$emergency_rate  =  $$emergency_share
$to_emergency    =  $emergency_rate * $surplus[summary]
$long_term_rate  =  1 - $$emergency_share
$to_long_term    =  $long_term_rate * $surplus[summary]

Read those four lines carefully, because they are the whole point of the exercise:

Set the two rate columns to Number, 4 places and the two amount columns to Money. The result:

Emergency rate   To emergency   Long term rate   To long term
        0.6000      $1,104.00           0.4000        $736.00

$1,104.00 + $736.00 = $1,840.00. Every cent of the surplus is allocated, and nothing was typed twice.

7 · Now change one number

Go back to B3 and type 0.2500. Press Enter.

Emergency rate   To emergency   Long term rate   To long term
        0.2500        $460.00           0.7500      $1,380.00

Both accounts moved, the total is still $1,840.00, and you edited one cell. Change a grocery bill and watch it travel the other way: expenses → surplus → both accounts. Sheets works out for itself which columns depend on which and calculates them in that order, so you never have to think about it.

8 · When it does not do what you expected

The fastest way to see what a sheet actually calculated — rather than what you meant — is to print it:

webgen-sheets --show ~/monthly-budget.wgsheet

That lists every panel, every value, and each column's formula beside its name, which is usually where the problem is hiding. The file itself is plain JSON and worth opening in Edit: the data is a simple grid of text, and the panels sit beside it.

What the error values mean

#REFA name that is not there. Usually a heading was renamed and the formula points at what it used to be called — or a $$rate that was never defined.
#VALUESomething in the sum is not a number. Text in a cell a formula is trying to multiply.
#DIV0Divided by zero.
#CYCLETwo columns each wait for the other. Sheets reports it rather than looping forever.
#NAMEA function it does not know, or something that is not a cell address. It knows SUM AVG MIN MAX COUNT.
BlankNot an error. A row nobody has filled in computes to nothing, because a sheet full of blank rows waiting for data should not look broken.

Three things that catch people out

9 · Where to go next