Formulas

The formula language, its functions, and where it differs from what you know.

The formula language follows Google Sheets: its operators and their order, its coercions, its errors. A formula you would type there reads the same here. What is built is a small part of it: 33 functions, one value per formula, no dates.

A1
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
What
Result
As typed
Powers are worked out left to right
64
=2^3^2
A minus sign in front binds first
4
=-2^2
Text is joined with &
Units: 120
="Units: "&120
A percentage is a number
15
=50%*30
Rounded to two places
3.33
=ROUND(10/3, 2)
A condition
more
=IF(B6>3, "more", "less")
An error says what went wrong
#DIV/0!
=1/0
An error caught
none
=IFERROR(1/0, "none")
A formula that needs itself
#CYCLE!
=B10+1
A blank counts as zero
1
=B20+1
Text that reads as a number counts
6
="3"*2

Column B holds the formulas, column C shows how each was typed. Type over either.

What a cell holds

A cell keeps what was typed, as text. With = in front it is a formula. Anything else is a value: a number (12, -1.5, .5, 1e3, 12%), TRUE or FALSE, or words. A leading apostrophe keeps what follows as words: '0123, '=A1.

Operators

From the one that binds first to the one that binds last:

OperatorWhat it does
- in front, % behinda sign and a percentage: -2^2 is 4, 50% is 0.5
^a power, worked out left to right: 2^3^2 is 64
* /times, divided by
+ -plus, minus
&joins two values as text
= <> < <= > >=compares; text is compared without regard to case

A blank cell counts as 0, as empty text or as FALSE, by what stands beside it. Text that reads as a number counts as one in arithmetic: ="3"*2 is 6.

References

A cell is named by its column and row (B3), a range by two corners (A1:C3). A $ anchors what follows it: when a formula is copied, B3 moves along, $B$3 stays, and $B3 keeps its column. A reference that leaves the sheet becomes #REF!. Whole columns and rows (A:A, 1:1), other sheets and named ranges are not built.

Functions

ABSANDAVERAGEAVERAGEIFCONCATCONCATENATECOUNTCOUNTACOUNTIFIFIFERRORINTLEFTLENLOWERMAXMEDIANMIDMINMODNOTORPOWERPRODUCTRIGHTROUNDROUNDDOWNROUNDUPSQRTSUMSUMIFTRIMUPPER

The names are English in every language, and arguments are separated by , or ; alike. A formula gives one value: a range where one value is expected is #VALUE!, and nothing fills the cells below.

Errors

A cell showsWhen
#DIV/0!a division by zero, an average of nothing
#VALUE!a value of the wrong kind: words where a number is needed, a range where one value is
#REF!a reference to a cell outside the sheet
#NAME?a function the engine does not know
#NUM!a number that cannot be: =SQRT(-1)
#N/Aa function given too few or too many arguments
#CYCLE!cells that need each other in a circle; every cell of the circle shows it
#ERROR!a formula that cannot be read: =1+

An error travels: a cell that reads one shows it too. IFERROR catches it.

Where it differs

  • Cells in a circle show #CYCLE!, where Sheets shows #REF!.
  • Text is compared letter by letter without regard to case, not in a language's alphabet.
  • The criteria of SUMIF, COUNTIF and AVERAGEIF know no wildcards (*, ?).
  • CONCAT takes any number of arguments, ranges too.
  • An argument cannot be left out between two separators: =IF(A1,,1) cannot be read.
  • Of the errors, only #REF! can be written into a formula.
  • Brackets and calls nest 64 deep at most.

Numbers and languages

A sheet keeps every number one way: a decimal point, no thousands separators. The grid shows and takes them the reader's way, so in German 12,5 typed into a cell is the number 12.5 and reads 12,5. Inside a formula a number always has a decimal point, in every language.

In code

The calculation is one function of the engine: createEvaluator(get) works a sheet out from a function that answers a cell's input, each cell once, on first asking. The sheet and the editor call it for you (sheet.evaluator(), editor.value(row, col)). shiftFormula moves a formula's references the way copy and paste does, parseInput reads a typed value, and FUNCTIONS is the list above.