Formulas cheat sheet
Using formulas in the spreadsheet.
Navigation
Operators
Precedence | Symbol | Description |
---|---|---|
1 |
| Percent (divides by 100) |
2 |
| positive |
| negative | |
3 |
| cell range |
4 |
| numeric range |
5 |
| Exponentiation |
6 |
| Multiplication |
| Division | |
7 |
| Addition |
| Subtraction | |
8 |
| String concatenation |
9 |
| Equal comparison |
| Not equal comparison | |
| Less than comparison | |
| Greater than comparison | |
| Less than or equal to comparison | |
| Greater than or equal to comparison |
Math Functions
Function | Description |
---|---|
| Adds all values in range and returns 0 if given no values. |
| Evaluates each value based on some criteria, and then adds the ones that meet those criteria. If |
| Multiply all values in the range. Returns 1 if given no values. |
| Return the absolute value of a number. |
| Returns the square root of a number. |
| Returns π, the constant. |
| Returns τ, the circle constant equal to 2π. |
Trig Functions
Function | Description |
---|---|
| Converts radians to degrees. |
| Converts degrees to radians. |
| Returns the sine of an angle in radians. |
| Returns the inverse sine of a number, in radians, ranging from 0 to π. |
| Returns the cosine of an angle in radians. |
| Returns the inverse cosine of a number, in radians, ranging from 0 to π. |
| |
| Returns the tangent of an angle in radians. |
| Returns the inverse tangent of a number, in radians, ranging from -π/2 to π/2. |
| Returns the cosecant of an angle in radians. |
| Returns the inverse cosecant of a number, in radians, ranging from -π/2 to π/2. |
| Returns the secant of an angle in radians. |
| Returns the inverse secant of a number, in radians, ranging from 0 to π. |
| Returns the cotangent of an angle in radians. |
| Returns the inverse cotangent of a number, in radians, ranging from 0 to π. |
| Returns the hyperbolic sine of an angle in radians. |
| Returns the inverse hyperbolic sine of a number, in radians. |
| Returns the hyperbolic cosine of an angle in radians. |
| Returns the inverse hyperbolic cosine of a number, in radians. |
| Returns the hyperbolic tangent of an angle in radians. |
| Returns the inverse hyperbolic tangent of a number, in radians. |
| Returns the hyperbolic cosecant of an angle in radians. |
| Returns the inverse hyperbolic cosecant of a number, in radians. |
| Returns the hyperbolic secant of an angle in radians. |
| Returns the inverse hyperbolic secant of a number, in radians. |
| Returns the hyperbolic cotangent of an angle in radians. |
| Returns the inverse hyperbolic cotangent of a number, in radians. |
Statistics Functions
Function | Description |
---|---|
| Returns the arithmetic mean of all values. |
| Evaluates each value based on some criteria, and then computes the arithmetic mean of the ones that meet those criteria. If |
| Returns the number of numeric values. |
| Evaluates each value based on some criteria, and then counts how many values meet those criteria. |
| Counts how many values in the range are empty. Cells with formula or code output of an empty string are also counted. |
| Returns the smallest value. Returns +∞ if given no values. |
| Returns the largest value. Returns -∞ if given no values. |
Logic Functions
These functions treat FALSE
and 0
as "falsey" and all other values are "truthy."
When used as a number, TRUE
is equivalent to 1
and FALSE
is equivalent to 0
.
Function | Description |
---|---|
| Returns |
| Returns |
| Returns |
| Returns |
| Returns |
| Returns |
| Returns |
String Functions
| Concatenates all values as strings. |
Lookup Functions
| Returns the value of the cell at a given location. |
VLOOKUP
VLOOKUP(search_key, search_range, output_col, [is_sorted])
Examples:
VLOOKUP(17, A1:C10, 3)
VLOOKUP(17, A1:C10, 2, FALSE)
Searches for a value in the first vertical column of a range and return the corresponding cell in another vertical column, or an error if no match is found.
If is_sorted
is TRUE
, this function uses a binary search algorithm, so the first column of search_range
must be sorted, with smaller values at the top and larger values at the bottom; otherwise the result of this function will be meaningless. If is_sorted
is omitted, it is assumed to be false
.
If any of search_key
, output_col
, or is_sorted
is an array, then they must be compatible sizes and a lookup will be performed for each corresponding set of elements.
HLOOKUP
HLOOKUP(search_key, search_range, output_row, [is_sorted])
Examples:
HLOOKUP(17, A1:Z3, 3)
HLOOKUP(17, A1:Z3, 2, FALSE)
Searches for a value in the first horizontal row of a range and return the corresponding cell in another horizontal row, or an error if no match is found.
If is_sorted
is TRUE
, this function uses a binary search algorithm, so the first row of search_range
must be sorted, with smaller values at the left and larger values at the right; otherwise the result of this function will be meaningless. If is_sorted
is omitted, it is assumed to be false
.
If any of search_key
, output_col
, or is_sorted
is an array, then they must be compatible sizes and a lookup will be performed for each corresponding set of elements.
XLOOKUP
XLOOKUP(search_key, search_range, output_range, [fallback], [match_mode], [search_mode])
Examples:
XLOOKUP("zebra", A1:Z1, A4:Z6)
XLOOKUP({"zebra"; "aardvark"}, A1:Z1, A4:Z6)
XLOOKUP(50, C4:C834, B4:C834, {-1, 0, "not found"}, -1, 2)
Searches for a value in a linear range and returns a row or column from another range.
search_range
must be either a single row or a single column.
Match modes
There are four match modes:
0 = exact match (default)
1 = next smaller
1 = next larger
2 = wildcard
Search modes
There are four search modes:
1 = linear search (default)
1 = reverse linear search
2 = binary search
2 = reverse binary search
Linear search finds the first matching value, while reverse linear search finds the last matching value.
Binary search may be faster than linear search, but binary search requires that values are sorted, with smaller values at the top or left and larger values at the bottom or right. Reverse binary search requires that values are sorted in the opposite direction. If search_range
is not sorted, then the result of this function will be meaningless.
Binary search is not compatible with the wildcard match mode.
Result
If search_range
is a row, then it must have the same width as output_range
so that each value in search_range
corresponds to a column in output_range
. In this case, the search axis is vertical.
If search_range
is a column, then it must have the same height as output_range
so that each value in search_range
corresponds to a row in output_range
. In this case, the search axis is horizontal.
If a match is not found, then fallback
is returned instead. If there is no match and fallback
is omitted, then returns an error.
If any of search_key
, fallback
, match_mode
, or search_mode
is an array, then they must be compatible sizes and a lookup will be performed for each corresponding set of elements. These arrays must also have compatible size with the non-search axis of output_range
.
Arrays
An array can be written using {}
, with ,
between values within a row and ;
between rows. For example, {1, 2, 3; 4, 5, 6}
is an array with two rows and three columns:
1 | 2 | 3 |
4 | 5 | 6 |
Arrays cannot be empty and every row must be the same length.
Numeric ranges (such as 1..10
) and cell ranges (such as A1:A10
) also produce arrays. All operators and most functions can operate on arrays, following these rules:
Operators always operate element-wise. For example,
{1, 2, 3} + {10, 20, 30}
produces{11, 22, 33}
.Functions that take a fixed number of values operate element-wise. For example,
NOT({TRUE, TRUE, FALSE})
produces{FALSE, FALSE, TRUE}
.Functions that can take any number of values expand the array into individual values. For example,
SUM({1, 2, 3})
is the same asSUM(1, 2, 3)
.
When arrays are used element-wise, they must be the same size. For example, {1, 2} + {10, 20, 30}
produces an error.
When an array is used element-wise with a single value, the value is expanded into an array of the same size. For example, {1, 2, 3} + 10
produces {11, 12, 13}
.
Criteria
Some functions, such as SUMIF()
, take a criteria parameter that other values are compared to. A criteria value can be a literal value, such as 1
, FALSE
, "blue"
, etc. A literal value checks for equality (case-insensitive). However, starting a string with a comparison operator enables more complex criteria:
Symbol | Description |
| Equal comparison |
| Not-equal comparison |
| Less-than comparison |
| Greater-than comparison |
| Less-than-or-equal comparison |
| Greater-than-or-equal comparison |
For example, COUNTIF(A1:A10, ">=3")
counts all values greater than or equal to three, and COUNTIF(A1:A10, "<>blue")
counts all values not equal to the text "blue"
(excluding quotes).
Numbers and booleans are compared by value (with TRUE
=1 and FALSE
=0), while strings are compared case-insensitive lexicographically. For example, "aardvark"
is less than "Camel"
which is less than "zebra"
. "blue"
and "BLUE"
are considered equal.
Wildcards
Wildcard patterns can be used …
… When using a criteria parameter with an equality-based comparison (
=
,==
,<>
,!=
, or no operator)… When using the
XLOOKUP
function with amatch_mode
of2
In wildcards, the special symbols ?
and *
can be used to match certain text patterns: ?
matches any single character and *
matches any sequence of zero or more characters. For example, DEFEN?E
matches the strings "defence"
and "defense"
, but not "defenestrate"
. *ATE
matches the strings "ate"
, "inflate"
, and "late"
, but not "wait"
. Multiple ?
and *
are also allowed.
To match a literal ?
or *
, prefix it with a tilde ~
: for example, COUNTIF(A1:A10, "HELLO~?")
matches only the string "Hello?"
(and uppercase/lowercase variants).
To match a literal tilde ~
in a string with ?
or *
, replace it with a double tilde ~~
. For example, COUNTIF(A1:A10, "HELLO ~~?")
matches the strings "hello ~Q"
, "hello ~R"
, etc. If the string does not contain any ?
or *
, then tildes do not need to be escaped.
Last updated