Formulas cheat sheet

Using formulas in the spreadsheet.

Operators

Math Functions

Trig Functions

Stats Functions

Logic Functions

String Functions

Lookup Functions

Arrays

Criteria

Wildcards

Operators

Math Functions

Trig Functions

Statistics Functions

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.

String Functions

Lookup Functions

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 = 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:

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:

  1. Operators always operate element-wise. For example, {1, 2, 3} + {10, 20, 30} produces {11, 22, 33}.

  2. Functions that take a fixed number of values operate element-wise. For example, NOT({TRUE, TRUE, FALSE}) produces {FALSE, FALSE, TRUE}.

  3. Functions that can take any number of values expand the array into individual values. For example, SUM({1, 2, 3}) is the same as SUM(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:

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 a match_mode of 2

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.

Unimplemented list

This is the list of Formulas that we are currently building and will be adding in the near future. If there is a Formula that is not implemented and not on this list please contact us.

Last updated