In sheet mode, a cell whose text starts with = is a formula. The cell keeps the formula and shows what it works out to, and the sheet works it out again whenever a cell it reads changes. The engine is the library's own, with no dependencies, and it is also published on its own as @nubisco/ui/formula.
Writing a formula
Type = in a cell, or in the formula bar above the grid, and then the formula. The formula bar shows the active cell's reference and its contents, a formula as written rather than its result.
- References name a cell,
B3, or a range,B2:B9. A whole column isC:Cand a whole row is3:3, both as far as the sheet's data reaches. $fixes a part of a reference:$A$1stays put when the formula is filled or pasted elsewhere,$A1keeps its column andA$1its row. Without$, a reference moves with the formula.- Point instead of typing: while a formula waits for an operand, after
=, a bracket, an operator or a separator, a click on a cell writes its reference, and a drag writes a range. In a cell opened by typing, the arrow keys do the same, andShiftwith them makes a range. - Functions are offered as their name is typed.
↑and↓move through the list, andTaborEnterwrites the function and its opening bracket. Inside the brackets, the function's arguments show under the field, the current one in bold.
While a formula is being edited, each reference has a colour, the same in the text and in a box on the grid around the cells it names.
Operators
| Operator | Meaning | Example |
|---|---|---|
+ - * / | Arithmetic | =B2*C2 |
^ | Power | =2^10 |
% | Percent, after a number | =B2*15% |
& | Joins text | =A2&" (draft)" |
= <> < > <= >= | Comparisons, TRUE or FALSE | =B2>=100 |
: | A range | =SUM(B2:B9) |
Comparisons ignore the case of text, as a desktop spreadsheet's do. An empty cell is 0 in arithmetic and empty text when joined.
Dates and times
A date is a number: the days since 30 December 1899, with the time of day as the fraction, so 19 November 2026 is 46345 and noon that day is 46345.5. Dates subtract to a number of days and add days the same way: =B2-A2 is the days between two dates and =A2+30 the date a month on. A date typed into a cell, as 2026-11-19 or in the locale's short form, is stored as its number and given a date format, and a formula such as =TODAY() or =DATE(2026,11,19) shows as a date until its cell has a format of its own. Text such as "2026-11-19" reads as a date wherever a date is expected.
TODAY() and NOW() read the clock when the sheet works its formulas out, which is whenever a cell changes.
Arrays
A formula can hold a small table of constants in braces: {1,2,3} is a row, {1;2;3} a column, and {1,2;3,4} two rows of two. Any function that takes a range takes an array: =SUM({1,2,3}), =INDEX({"Low","Mid","High"},2), =VLOOKUP(B2,{0,"F";50,"C";70,"B";90,"A"},2). A cell shows one value, so a formula that ends in an array of more than one value is #VALUE!.
Your locale's syntax
A formula is typed and shown in the sheet's locale. Where the decimal separator is a comma, as in pt-PT or de-DE, arguments are separated with semicolons and decimals take the comma: =ROUND(B2*1,23;2). Inside an array the columns are then separated with a backslash and the rows with a semicolon, {1,5\2,5;3\4}. The cell stores the formula in one canonical form, =ROUND(B2*1.23,2), so the same cells read the same in every locale. Function names are always in English.
Errors
A formula that cannot be worked out shows an error code in the danger colour, and the cell's tooltip says why.
| Error | Means |
|---|---|
#DIV/0! | A division by zero |
#VALUE! | A value of the wrong kind, such as text in arithmetic |
#REF! | A reference that leaves the sheet, or a circular reference |
#NAME? | A function the engine does not know |
#N/A | A lookup found nothing, or a function had the wrong number of values |
#NUM! | A number out of range, such as the square root of a negative |
#ERROR! | The formula itself does not parse |
A cell that reads a cell with an error shows that error too, so the first one in a chain is the one to fix.
Filling, copying and pasting
The fill handle, Ctrl+D and Ctrl+R copy a formula and move its references with it: =B2*C2 filled down becomes =B3*C3, =B4*C4 and so on, while the parts fixed with $ stay. Pasting a formula copied from the same sheet moves it the same way, by the distance between the copy and the paste. A cut and paste moves the formula unchanged, as a desktop spreadsheet does.
Turning formulas off
A sheet whose text may start with = without being a formula sets :formulas="false". The cells then show their text as it is, and the formula bar is hidden unless formula-bar asks for it.
The engine on its own
@nubisco/ui/formula works out formulas without a sheet on the page, for a server, a worker or a test. It reads the same cells as sheet mode.
import { createFormulaSheet, isFormulaError } from '@nubisco/ui/formula'
const sheet = createFormulaSheet()
const values = sheet.compute({ A1: 120, A2: 80, A3: '=SUM(A1:A2)' })
values.get('A3') // 200
const result = values.get('B1')
if (isFormulaError(result)) console.warn(result.error, result.message)compute returns the result of every formula cell, keyed by reference, and keeps each formula's parse for the next call, so a change re-reads only the formulas whose text changed. It also exports the tokenizer, shiftFormula for moving references, toCanonical and toLocalized for the locale syntax, and FORMULA_FUNCTIONS, the list this page's reference is built from.
Functions
Math
| Function | Syntax | Description |
|---|---|---|
ABS | ABS(value) | Returns a number without its sign. |
CEILING | CEILING(value, [significance]) | Rounds a number up to the nearest multiple of a significance, 1 when left out. |
EXP | EXP(value) | Returns e raised to a power. |
FLOOR | FLOOR(value, [significance]) | Rounds a number down to the nearest multiple of a significance, 1 when left out. |
INT | INT(value) | Rounds a number down to the nearest integer. |
LN | LN(value) | Returns the natural logarithm of a number. |
LOG | LOG(value, [base]) | Returns the logarithm of a number in a base, 10 when left out. |
LOG10 | LOG10(value) | Returns the base 10 logarithm of a number. |
MOD | MOD(dividend, divisor) | Returns the remainder of a division, with the sign of the divisor. |
PI | PI() | Returns the number pi. |
POWER | POWER(base, exponent) | Raises a number to a power. |
PRODUCT | PRODUCT(value1, [value2, ...]) | Multiplies numbers and the numbers in ranges. |
ROUND | ROUND(value, [digits]) | Rounds a number to a number of digits, halves away from zero. |
ROUNDDOWN | ROUNDDOWN(value, [digits]) | Rounds a number toward zero to a number of digits. |
ROUNDUP | ROUNDUP(value, [digits]) | Rounds a number away from zero to a number of digits. |
SIGN | SIGN(value) | Returns 1 for a positive number, -1 for a negative one and 0 for zero. |
SQRT | SQRT(value) | Returns the square root of a number. |
SUM | SUM(value1, [value2, ...]) | Adds numbers and the numbers in ranges. |
SUMIF | SUMIF(range, criterion, [sum_range]) | Adds the cells that meet a criterion. |
SUMIFS | SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...]) | Adds the cells that meet every criterion. |
SUMPRODUCT | SUMPRODUCT(array1, [array2, ...]) | Multiplies matching cells of ranges of the same size and adds the products. |
TRUNC | TRUNC(value, [digits]) | Cuts a number to a number of digits without rounding. |
Statistical
| Function | Syntax | Description |
|---|---|---|
AVERAGE | AVERAGE(value1, [value2, ...]) | Returns the arithmetic mean of numbers and the numbers in ranges. |
AVERAGEIF | AVERAGEIF(range, criterion, [average_range]) | Returns the mean of the cells that meet a criterion. |
AVERAGEIFS | AVERAGEIFS(average_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...]) | Returns the mean of the cells that meet every criterion. |
COUNT | COUNT(value1, [value2, ...]) | Counts the numbers among the values and in ranges. |
COUNTA | COUNTA(value1, [value2, ...]) | Counts the values and the cells in ranges that are not empty. |
COUNTBLANK | COUNTBLANK(range) | Counts the empty cells in a range, including cells with empty text. |
COUNTIF | COUNTIF(range, criterion) | Counts the cells in a range that meet a criterion. |
COUNTIFS | COUNTIFS(criteria_range1, criterion1, [criteria_range2, criterion2, ...]) | Counts the positions where every criterion is met. |
LARGE | LARGE(range, k) | Returns the k-th largest number in a range. |
MAX | MAX(value1, [value2, ...]) | Returns the largest number, or 0 when there are none. |
MEDIAN | MEDIAN(value1, [value2, ...]) | Returns the middle number, or the mean of the two middle numbers. |
MIN | MIN(value1, [value2, ...]) | Returns the smallest number, or 0 when there are none. |
SMALL | SMALL(range, k) | Returns the k-th smallest number in a range. |
STDEV | STDEV(value1, [value2, ...]) | Returns the standard deviation of a sample. |
VAR | VAR(value1, [value2, ...]) | Returns the variance of a sample. |
Logical
| Function | Syntax | Description |
|---|---|---|
AND | AND(value1, [value2, ...]) | Returns TRUE when every value is true. |
FALSE | FALSE() | Returns the logical value FALSE. |
IF | IF(condition, [value_if_true], [value_if_false]) | Returns one value when a condition is true and another when it is false. |
IFERROR | IFERROR(value, value_if_error) | Returns a value, or a fallback when the value is any error. |
IFNA | IFNA(value, value_if_na) | Returns a value, or a fallback when the value is #N/A. |
IFS | IFS(condition1, value1, [condition2, value2, ...]) | Returns the value paired with the first condition that is true. |
NOT | NOT(value) | Returns the opposite of a logical value. |
OR | OR(value1, [value2, ...]) | Returns TRUE when at least one value is true. |
SWITCH | SWITCH(expression, case1, value1, [case2, value2, ...], [default]) | Compares a value with a list of cases and returns the value of the first match. |
TRUE | TRUE() | Returns the logical value TRUE. |
XOR | XOR(value1, [value2, ...]) | Returns TRUE when an odd number of values are true. |
Text
| Function | Syntax | Description |
|---|---|---|
CONCAT | CONCAT(value1, [value2, ...]) | Joins values and the cells of ranges into one text. |
CONCATENATE | CONCATENATE(value1, [value2, ...]) | Joins values into one text. |
EXACT | EXACT(text1, text2) | Returns TRUE when two texts are the same, including case. |
FIND | FIND(search_for, text, [start]) | Returns the position of a text inside another, matching case. |
LEFT | LEFT(text, [count]) | Returns the first characters of a text, one when the count is left out. |
LEN | LEN(text) | Returns the number of characters in a text. |
LOWER | LOWER(text) | Converts a text to lower case. |
MID | MID(text, start, count) | Returns characters from the middle of a text, counting from 1. |
PROPER | PROPER(text) | Capitalises the first letter of each word and lowers the rest. |
REPLACE | REPLACE(text, start, count, new_text) | Replaces a number of characters at a position, counting from 1. |
REPT | REPT(text, times) | Repeats a text a number of times. |
RIGHT | RIGHT(text, [count]) | Returns the last characters of a text, one when the count is left out. |
SEARCH | SEARCH(search_for, text, [start]) | Returns the position of a text inside another, ignoring case and allowing wildcards. |
SUBSTITUTE | SUBSTITUTE(text, old_text, new_text, [instance]) | Replaces occurrences of a text, or only the given occurrence. |
TEXT | TEXT(value, format) | Formats a number or date as text with a format code such as "#,##0.00", "0%" or "yyyy-mm-dd". |
TEXTJOIN | TEXTJOIN(delimiter, ignore_empty, value1, [value2, ...]) | Joins values with a delimiter, optionally leaving out empty ones. |
TRIM | TRIM(text) | Removes spaces from both ends and collapses runs of spaces inside. |
UPPER | UPPER(text) | Converts a text to upper case. |
VALUE | VALUE(text) | Converts a text that looks like a number into the number. |
Date and time
| Function | Syntax | Description |
|---|---|---|
DATE | DATE(year, month, day) | Returns the serial number of a date, rolling over months and days out of range. |
DATEDIF | DATEDIF(start_date, end_date, unit) | Returns the whole years (Y), months (M) or days (D) between two dates, or the remainders MD, YM and YD. |
DATEVALUE | DATEVALUE(text) | Converts an ISO date written as text into its serial number. |
DAY | DAY(date) | Returns the day of the month of a date, 1 to 31. |
DAYS | DAYS(end_date, start_date) | Returns the number of days between two dates. |
EDATE | EDATE(start_date, months) | Returns the date a number of months before or after another. |
EOMONTH | EOMONTH(start_date, months) | Returns the last day of the month a number of months before or after a date. |
HOUR | HOUR(time) | Returns the hour of a time, 0 to 23. |
ISOWEEKNUM | ISOWEEKNUM(date) | Returns the ISO 8601 week of the year, where weeks start on Monday. |
MINUTE | MINUTE(time) | Returns the minute of a time, 0 to 59. |
MONTH | MONTH(date) | Returns the month of a date, 1 to 12. |
NETWORKDAYS | NETWORKDAYS(start_date, end_date, [holidays]) | Counts the weekdays between two dates, inclusive, leaving out holidays. |
NOW | NOW() | Returns the current date and time, recalculated on every change. |
SECOND | SECOND(time) | Returns the second of a time, 0 to 59. |
TIME | TIME(hours, minutes, seconds) | Returns a time of day as a fraction of a day. |
TIMEVALUE | TIMEVALUE(text) | Converts a time written as text into a fraction of a day. |
TODAY | TODAY() | Returns today's date, recalculated on every change. |
WEEKDAY | WEEKDAY(date, [type]) | Returns the day of the week: type 1 counts Sunday as 1, type 2 Monday as 1, type 3 Monday as 0. |
WEEKNUM | WEEKNUM(date, [type]) | Returns the week of the year, with weeks starting on Sunday (type 1) or Monday (type 2). |
WORKDAY | WORKDAY(start_date, days, [holidays]) | Returns the date a number of weekdays after or before a date, skipping holidays. |
YEAR | YEAR(date) | Returns the year of a date. |
YEARFRAC | YEARFRAC(start_date, end_date, [basis]) | Returns the fraction of a year between two dates, by a day count basis from 0 to 4. |
Lookup and reference
| Function | Syntax | Description |
|---|---|---|
CHOOSE | CHOOSE(index, value1, [value2, ...]) | Returns the value at a position in a list of values, counting from 1. |
COLUMN | COLUMN([reference]) | Returns the column number of a reference, or of the current cell. |
COLUMNS | COLUMNS(range) | Returns the number of columns in a range. |
HLOOKUP | HLOOKUP(key, table, row, [approximate]) | Finds a key in the first row of a table and returns the value in another row of that column. |
INDEX | INDEX(range, row, [column]) | Returns the value at a row and column of a range, counting from 1. |
MATCH | MATCH(key, range, [match_type]) | Returns the position of a key in a row or column: 1 for sorted ascending, 0 for exact, -1 for sorted descending. |
ROW | ROW([reference]) | Returns the row number of a reference, or of the current cell. |
ROWS | ROWS(range) | Returns the number of rows in a range. |
VLOOKUP | VLOOKUP(key, table, column, [approximate]) | Finds a key in the first column of a table and returns the value in another column of that row. |
XLOOKUP | XLOOKUP(key, lookup_range, return_range, [if_not_found], [match_mode], [search_mode]) | Finds a key in a range and returns the matching item of another range, with a fallback when nothing matches. |
Information
| Function | Syntax | Description |
|---|---|---|
ISBLANK | ISBLANK(value) | Returns TRUE when a cell is empty. |
ISERROR | ISERROR(value) | Returns TRUE when a value is any error. |
ISLOGICAL | ISLOGICAL(value) | Returns TRUE when a value is TRUE or FALSE. |
ISNA | ISNA(value) | Returns TRUE when a value is the #N/A error. |
ISNUMBER | ISNUMBER(value) | Returns TRUE when a value is a number. |
ISTEXT | ISTEXT(value) | Returns TRUE when a value is text. |
NA | NA() | Returns the #N/A error, for a value that is not available. |