Skip to content

Expressions ​

Computed fields, showIf/validIf, onlyIf, initial values, and action updates are all written in the same formula language: a spreadsheet-style syntax with {field} references and a large built-in function library.

Writing a formula in the editor ​

Every place that takes a formula uses the same editor, so you only learn it once. It helps as you type:

  • Function suggestions. Type two or more letters of a function name, in any case (mult, MULT), and a list of matching functions appears. Press Tab to pick one and the editor writes it in capitals. Then type an opening bracket and the editor adds the closing one.
  • Field suggestions. Type { and the list changes to the fields of the current collection. Pick one and the cursor lands after the closing brace, ready for the next value.
  • The hint bar. Just above the box, a bar shows the function you're inside and each value it expects. The value you're typing is highlighted, with a short description beside it.
  • Live checks. The editor checks as you type. Red means the formula can't work: a bracket left open, or a function that doesn't exist. Orange means take a look: a function given fewer or more values than it usually takes, a field name that isn't on this collection, a unit or style that isn't one of the allowed words, or an ENUM option that isn't one of that field's options (the warning lists the real ones).
  • The full editor. For longer formulas, click the expand button in the box's corner. You get a bigger writing area and two reference panels: your fields with their types, and every function. The function search looks at names and descriptions, so typing sum finds SUMARRAY. Click Apply to send the formula back to the field.

Try a formula before you use it ​

Tools → Query Editor in the app admin evaluates a formula against your real data without saving or changing anything. Choose a collection and a record, type the formula, and click Evaluate (or press Ctrl+Enter). The result shows with a badge for its type: string, number, boolean, or null for a blank result. Try a formula here first, then paste it into the field, filter or card that needs it.

The Query Editor runs as the app's admin, so USERPROFILE("name") there returns the admin's name. A signed-in person in the app gets their own.

Referencing fields ​

  • {field}: a field on the current record.
  • {ref.field}: traverse a reference field to read a field on the linked record (e.g. {product.name}). Chains of references work too: {shift.location.name}.
  • {_THISRECORD.field}: inside a query condition, refers to the outer record the query was run from (as opposed to the candidate row currently being tested).
  • {_PREVROW.field} / {_NEXTROW.field}: the previous/next row in a list pass.
  • {_INDEX} / {_TOTAL}: the current position and total count in a list pass.
  • {_FORM.field}: a value entered into a form_action dialog.
  • {_THISUser.field}: the logged-in user's own record (id, email, name, etc.).

Logic ​

IF(cond, then, else), IFS(cond1, val1, cond2, val2, ..., default), SWITCH(value, match1, result1, match2, result2, ..., default), AND, OR, NOT, EQUAL, GT, LT, GTE, LTE, ISBLANK, ISEMAIL (true when the text looks like an email address; a blank value is not one, so an optional field uses OR(ISBLANK({email}), ISEMAIL({email})); to refuse a typo everywhere, not only in the app's own forms, set the text field's Must be an email address option instead), and ROLE("name") (checks a role name against the app's configured roles, handy inside EQUAL(USERPROFILE("role"), ROLE("admin"))), and ENUM("collection", "field", "option") (the same check for an enum option, handy inside EQUAL({status}, ENUM("orders", "status", "packed")); the editor suggests the collection, then its enum fields, then that field's options, and warns if any of them is wrong).

There are no +, -, *, /, >=, && or || operators: everything is a function call (ADD, SUBTRACT, GTE, AND, …).

Text ​

CONCATENATE, JOIN, UPPER, LOWER, TRIM, LEN, LEFT, RIGHT, CONTAINS, REPLACE, NUMBERFORMAT, MONEYFORMAT.

NUMBERFORMAT(value, decimals?) writes a number with thousands separators: NUMBERFORMAT(124000) is 124,000. Leave decimals out and it keeps up to two and drops trailing zeros (1234.5 is 1,234.5); give it and you get exactly that many (NUMBERFORMAT(1234.5, 2) is 1,234.50, NUMBERFORMAT(1234.567, 0) is 1,235). MONEYFORMAT(value, currency?, decimals?) does the same with a currency sign: MONEYFORMAT(124000) is ₦124,000.00, MONEYFORMAT(1500, "USD") is $1,500.00, and a loss is written -₦3,000.00. The currency is a code such as NGN (the default), KES or GBP (MONEYFORMAT(1500, "KES", 0) is KSh 1,500). Both round halves away from zero like ROUND, give blank for something that is not a number, and return text, so format last: CONCATENATE("Profit: ", MONEYFORMAT(SUBTRACT({income}, {expenses}))) works, but you can't add up the formatted result. A price field and a home screen formula card already show their own formatting; these are for sentences, receipts and PDFs.

Math ​

ADD, SUBTRACT, MULTIPLY, DIVIDE, MOD, POWER, SQRT, ROUND, MROUND, CEILING, FLOOR, PERCENT (what part of the whole is done, 0 to 100), ABS, MIN, MAX, AVERAGE, DISTANCEBETWEEN (for two geolocation values), LATITUDE and LONGITUDE (the two numbers inside a geolocation value), ADDRESS (the city, state or country of an address value, or all of it as text).

Dates ​

NOW(), TODAY(), YESTERDAY(), TOMORROW(), TIMENOW(), DATE, TIME, DAYOFWEEK, STARTOFDAY, ENDOFDAY, STARTOFMONTH(), ENDOFMONTH(), STARTOFYEAR, ENDOFYEAR, YEAR, MONTH, DAY, HOUR, MINUTE, WEEKDAY, DATEDIFF, DATEADD, DATEFORMAT, TIMEFORMAT, ISBEFORE, ISAFTER, ISBETWEEN. Compare dates with ISBEFORE / ISAFTER / ISBETWEEN, not GT / LT.

Generating values ​

RAND(min?, max?), UNIQUEID() and UNIQUECHAR(type, length) produce fresh random values. UNIQUECHAR("alphanumeric", 6) gives a short random code, where type is letters, numeric, alphanumeric, special, or all. They generate a new value every time they're evaluated, so use them as a field's initial value (which runs once when the create form opens), never in a computed field. UNIQUECHAR is random, not guaranteed unique; use UNIQUEID() when a value must never repeat.

Cross-collection queries ​

These look at other records, not just the current one:

  • COLLECTIONSELECT("collection", "condition"): every record matching the condition.

  • FILTER("collection", "condition"): same idea, lighter weight.

  • REF_ROWS("collection", "foreignKey"): shorthand for the common reverse-lookup case: every record in collection whose foreignKey field points back at this record. Equivalent to COLLECTIONSELECT("collection", "EQUAL({foreignKey},{_THISRECORD.id})"). Takes an optional third argument, REF_ROWS("collection", "foreignKey", "extraCondition"), AND-ed onto the auto-generated equality check. Drop to COLLECTIONSELECT/FILTER directly once you need anything beyond that (sorting, OR logic, multiple extra conditions).

  • SELECT("collection", "returnColumn", "condition"): just the values of one column.

  • EXISTS("collection", "condition"): true if any record matches.

  • Filtering a list the record already has. In FILTER, COLLECTIONSELECT, SELECT, EXISTS, ORDERBY and ORDERBYDESCENDING, the first argument can be a {list field} instead of a quoted collection name. A completelist is a list of records; written in braces it is used as it is, with nothing read again, and the condition runs only over those rows. In the condition, {field} is a field of each row of the list and {_THISRECORD.field} is the record you are on:

    • FILTER({tasks}, EQUAL({status}, "open")): the open ones, as a list you can show in another completelist field.
    • COUNT(FILTER({tasks}, EQUAL({status}, "open"))): how many.
    • SUMARRAY(SELECT({tasks}, "hours", EQUAL({status}, "open"))): their hours added up.
    • EXISTS({tasks}, EQUAL({status}, "blocked")): is any blocked?
    • ORDERBY({tasks}, "title", EQUAL({status}, "open"), "title"): their titles, in order.

    A quoted name still means "read that collection", so existing formulas are unchanged. The braces tell the two apart. A list can be filtered again (FILTER(FILTER({tasks}, …), …)). The field must be a list of records (a completelist); a text or number field gives nothing.

  • COUNT(...), FIRST(...), LAST(...), SUMARRAY(...): operate on the array a query returns. COUNT also works on a multi-select field: COUNT({symptoms}) is how many options are ticked (0 for none). Use IN("bleeding", {symptoms}) to test whether one option is among them. Both also work through a reference, e.g. COUNT({questionnaire.symptoms}).

  • LOOKUP(value, "collection", "lookupColumn", "returnColumn"): single-value lookup.

  • ORDERBY / ORDERBYDESCENDING: sorted query results.

  • USERPROFILE("field"): a field from the current user's profile record.

  • SETTINGS("field"): a field from the app's settings record, a value everyone shares, such as a commission rate or a business name: MULTIPLY({total}, DIVIDE(SETTINGS("vendor_percentage"), 100)). Mark one collection This holds the app's settings in the collection editor; it keeps exactly one record, which the app creates, and opens as a single form instead of a list. Everyone who is signed in can read it, so the formulas work for every role; on the role's permissions page its row has just one choice, Can edit, for who may change it. To keep a value from a role, hide that field for the role under Hidden fields (it then reads blank for them). It has no Create or Delete. It works anywhere USERPROFILE() does, and a computed field that uses it follows the setting when it changes, so keep a value that must not change (a price on an old order) in a stored field, copied when the record is made.

  • HERE(): the device's current geolocation.

Writing condition arguments

The condition argument of COLLECTIONSELECT / FILTER / EXISTS / SELECT / ORDERBY is evaluated per row. Write it as a plain expression, just like any other argument:

EXISTS("cartitem", EQUAL({product}, {_THISRECORD.product}))

The older style of passing the condition as a quoted string (EXISTS("cartitem", "EQUAL({product}, {_THISRECORD.product})")) still works, but a quoted condition can't contain string literals of its own, so prefer the plain form.

For every function with its exact parameters, see the Schema Reference.

Special-purpose ​

  • IN(value, list): true if value appears anywhere in an array.

  • IFS(...): first matching condition wins; the trailing argument is the default.

  • SWITCH(value, match1, result1, match2, result2, ..., default): compares one value with several options and gives the result of the first one that is equal; the trailing argument is the default, and with no match and no default the result is blank. Use it instead of IFS whenever you would repeat EQUAL({field}, ...) on the same field, for example to turn a status into a progress number:

    SWITCH({status},
      "new", 10, "confirmed", 20, "washing", 40,
      "delivered", 100, "cancelled", 0, 0)

    It compares exactly as EQUAL does (the number 1 is not equal to the text "1"), and a blank value takes the default. When the value is a choice field of the same collection, the editor warns if a match is not one of its options, so a typo or a renamed option can't quietly fall through to the default.

Good to know ​

A few behaviours that are easy to trip over:

  • NOW() vs TODAY(). NOW() is the exact moment, with the time, so it changes every second. TODAY() is the start of today (midnight), the same all day. Use TODAY() for anything measured in days, and NOW() only when the time of day matters.
  • DATEDIFF(a, b, unit) is a minus b. Put the later date first: DATEDIFF(TODAY(), {date_created}, "days") is how many days ago a record was created. The other way round gives a negative number. The result is a whole number, with the fraction cut off. The unit is seconds, minutes, hours, days, weeks, months or years.
  • DATEADD(date, n, unit) takes the same units. DATEFORMAT(date, style) turns a date into readable text; the style is long (31 October 2026), short, month or iso. TIMEFORMAT(date, style) does the same for the time of day: 24h (the default, 14:30) or 12h (2:30 PM). It also reads a plain time like "14:30", so TIMEFORMAT({starts}, "12h") works on a time field.
  • Dividing can leave long decimals. DIVIDE(8500, 3) is 2833.3333333333335. Wrap it in ROUND(value, decimals) to tidy it up: ROUND(DIVIDE({amount}, 3), 2) gives 2833.33. DIVIDE returns null when you divide by zero.
  • Rounding to tens, hundreds, or any step. ROUND also takes a negative number of places: ROUND(1234, -2) is 1200. To round to a multiple that isn't a power of ten, use MROUND(value, multiple): MROUND(1234, 10) is 1230, MROUND(1260, 100) is 1300, and MROUND(1234, 50) is 1250, handy for prices to the nearest ₦5 or ₦50. CEILING(value, multiple) always goes up to the next multiple (CEILING(1201, 100) is 1300) and FLOOR(value, multiple) always goes down (FLOOR(1299, 100) is 1200); leave the multiple out and it is 1, so CEILING(2.1) is 3. A number that is exactly halfway rounds away from zero (ROUND(2.5) is 3, ROUND(-2.5) is -3), and ROUND(1.005, 2) is 1.01. A blank or non-number gives blank.
  • ENUM and ROLE return blank on a mismatch. ENUM("orders", "status", "Piad") and ROLE("mangr") give null instead of passing the typo through, and for ENUM the editor also warns you with the real options. Using them for names that matter means a renamed option or role shows up straight away, instead of a formula that silently never matches.
  • A reference is a doorway. {customer.name} reads the name of the customer the order points at; {assigned_to.name} works the same through any other reference.
  • LOOKUP(value, collection, lookupColumn, returnColumn) is for when you have a plain value and no reference to follow: LOOKUP("Ada Obi", "customers", "name", "phone") finds the customer called Ada Obi and gives back her phone number. If a field is a reference, {ref.field} is simpler.

Size limits ​

Formulas run on every device that opens your app, and some run on the platform's servers, so they are kept to a sensible size. You will not meet these limits writing normal formulas (the longest formula in our example apps is about 500 characters), but they are there:

LimitValueWhat happens past it
Length of one formula10,000 charactersThe editor says it is too long, and the schema is not saved.
Parts in one formula (names, values, brackets, commas)2,000The same: "too complex".
Nesting, as in ADD(ADD(ADD(...)))64 levelsThe same: "nested too deeply".
Text built by CONCATENATE, JOIN or REPLACE, or held by a calculated field500,000 charactersThe formula reads as empty (blank), like any formula that can't be worked out.

Two things to know:

  • A calculated field that feeds another that feeds another can only grow so far. If each field repeats the one before it (CONCATENATE({a}, {a}), then CONCATENATE({b}, {b})...), the text doubles at every step. It stops at the 500,000-character limit, and the field that would pass it reads as empty, along with the ones built on it.
  • An imported or template schema with an over-size formula is refused with a message that names where it is (for example orders > schema > total > computed > expression), so it never reaches an app.

Released under no license yet — internal product, pre-launch.