PadCodedocs

Formulas

Work values out from your data: the formula language in plain words, where you write formulas, and what their errors mean.

A formula works a value out from other values: price * quantity, count > 0, 'Hi, ' + name. Link a setting to a formula and it shows the answer, worked out again whenever the values it uses change. Formulas also decide things, like whether a view shows or which way an If step goes.

This page is the friendly tour. Every detail, with a tested example of each, is in the Formula language reference.

The Formula sheet with count + 1 typed in, and Right now: 1 under it.

#Where you write formulas

WhereHow
A setting in the Style tab, or in a step's settingsTap ⚡︎ beside it and choose Formula…. The setting shows the formula as a chip: ƒ count + 1.
Show when, in the Style tab's Show & enableType a condition in the box, like count > 0. A note under the box says what's wrong, if anything.
An If's Condition, the Where of Update in List and Remove from ListType it in the box, or tap the ƒ button beside it to open the Formula sheet.
TextPut a formula in braces: {count * 2} cups. See Text with values.

#The Formula sheet

Formula… in the ⚡︎ menu, and the ƒ button beside a condition, open the Formula sheet. From top to bottom:

  • Describe it: say what the formula should work out, in your own words, and tap Write it (or Return). See Writing a formula from words.
  • The formula, in a box. An empty box suggests one: e.g. total * (1 + tip) / people.
  • The answer, as you type. In green, Right now: and the result, worked out with your variables' starting values. In orange, what's wrong.
  • Names you can use here, in groups: From this action (like it or error.message), App data (your variables), Screen inputs (params.name) and Repeater item (item.title). Tap one to add it.
  • How formulas work, a card with each kind of formula and an example. Tap an example to add it.
  • Every function, by kind, with what it takes and what it does. Tap one to add it with its opening bracket.

Tap Done to keep the formula, or Cancel to leave without changing anything.

#Writing a formula from words

Not sure how to write it? Type what it should work out in Describe it, like "how many days I stayed on the diet" or "each person's share of the total, with the tip", and tap Write it. In a second or two the formula appears in the box below, written from the names you can use here (your variables, with what they hold now, and the rest of the list above), and the Formula sheet's green Right now: shows what it works out to. Check it, change it if you like, then tap Done.

  • PadCode checks the formula before you see it; if it doesn't work, the AI is told why and writes it again once. If it still doesn't, the sheet says what's wrong.
  • With a formula in the box already, Describe it changes that one: "round it to 2 places".
  • It's part of PadCode Pro: on Free, Write it shows what Pro adds. It uses PadCode's quick AI model, through PadCode's server, so it needs a connection.
  • The first time, PadCode asks Send this to the AI model?: what you described, and the names you can use with what they hold now, go to PadCode's server and on to the AI model, which another company runs. Allow writes it, and PadCode doesn't ask again; Not Now sends nothing.
  • It only writes the formula: nothing changes until you tap Done.
Describe it: a formula written from words, checked, with what it works out to.
The Formula sheet: App data names to tap, and the How formulas work card with an example of each kind.

#Values

WriteWhat it is
12, 3.5A number. Put a minus in front for a negative one: -3.
'Hello' or "Hello"Text, in quotes. To put the same quote inside, type a backslash before it: 'It\'s'.
true, falseTrue and false.
nullNo value at all.
[1, 2, 3]A list, in square brackets.

#Names

A name reads a value. It must match exactly, capital letters included.

NameWhat it reads
countOne of your variables.
params.nameA value this screen was opened with: one of its Screen inputs.
itemInside a Repeater: the current item.
itEach item, in turn: inside filter, find, map and sort, in the steps of Repeat for Each, and in the Where of Update in List and Remove from List.
errorInside Try's Catch: what went wrong. error.message says it in words; after a Call API, error.status and error.body hold the server's answer.
eventWhat some triggers give their steps, like event.newValue when a value changes.
pastedIn a Paste Button's steps: the text that was pasted.
themeYour Asset Colors, by name: theme.brand.light is the light version of the color named brand.

Where each of these exists, exactly, is in Special names.

#Reading inside a value

WriteWhat it reads
user.nameOne field of a record.
items[0]One item of a list. The first is 0, the second 1.
user['name']A field by its name in quotes, the same as user.name.
catalog.products[0].titleAny mix of the two, as deep as you need.

A field that isn't there, or an item past the end of the list, gives null instead of an error. So does a dot after null: if user is empty, user.name is null. That makes ?? handy: user.name ?? 'Guest'.

#Operators

WriteMeansExampleGives
+ - * /Add, subtract, multiply, divideprice * 2, with price 4.59
%The remainder after dividing7 % 21
+ with textJoins text together'Hi, ' + name, with name AdaHi, Ada
== !=Equal, not equalsize == 'L'true or false
< > <= >=Less, more, at most, at leastcount > 0true or false
&&And: both are trueisOn && count > 0true or false
||Or: at least one is trueisAdmin || isOwnertrue or false
!Not: flips true and false!donetrue or false
??The value after it, when the one before is nullnickname ?? 'Guest'Guest, while nickname is null
? :Picks one: condition ? if true : if falsedone ? 'Yes' : 'No'Yes or No
( )Works this part out first(1 + tip) * total

Formulas work out *, / and % first, then + and -, then comparisons, then &&, then ||, then ??, and ? : last. Add brackets whenever you're not sure. The full order is in Which part is worked out first.

A few things to know:

  • Numbers compare by size, text letter by letter, with capital letters before lowercase ones. Dates are kept as text like 2026-10-28T09:00:00Z, so comparing two dates compares their times. Comparing a number with text is an error.
  • == compares exactly. The number 1 and the text '1' aren't equal.
  • + joins as soon as one side is text. What people type in a Text Field is text, so '5' + 1 gives 51. Turn text into a number first: number(qty) + 1. Other math with text, like '5' * 2, is an error.
  • / keeps decimals. 7 / 2 is 3.5. Some decimals print long, like 0.1 + 0.2 showing 0.30000000000000004: use round(x, 2), fixed(x, 2) or currency(x) to show them neatly.
  • ?? only replaces null. Empty text is still text, and a Text variable starts as empty text, not null. For text, use isEmpty(nickname) ? 'Guest' : nickname.

#True and false

Conditions, like Show when and an If's Condition, accept any value. false, null, 0, empty text and an empty list count as false; everything else counts as true. So nickname on its own is true when it holds some text, and items is true when the list has something in it.

!, && and || treat values the same way, and always give true or false.

#Functions

A function does a job on the values you give it, in brackets: round(total, 2), uppercase(name), count(tasks). Functions can go inside each other: count(filter(tasks, !it.done)). In filter, find, map and sort, it is each item of the list in turn.

Every function, with what it takes and what it gives back, is in Formula functions.

#Examples

FormulaWithGives
price * quantityprice 4.5, quantity 29
total * (1 + tip) / peopletotal 100, tip 0.2, people 430
round(7 / 3, 2)2.33
'Hello, ' + namename AdaHello, Ada
score >= 50 ? 'Pass' : 'Try again'score 72Pass
!done && count > 0done false, count 3true
user.nameuser, a record with the field name: AdaAda
items[0].titleitems, a list of recordsthe first item's title
count(items)items with 3 items3
isEmpty(trim(email))email " " (only spaces)true
number(qtyText) ?? 0qtyText "abc"0
params.ida screen opened with id 77
sum(map(items, it.qty * it.rate))two items: 1 × 1200 and 4 × 851540
formatDate(addDays(today(), 14), 'long')the date two weeks from today, written out

#When a formula is wrong

PadCode checks formulas as you write them. The Formula sheet shows the problem in orange under the box, Show when and conditions show it under their box, and Issues lists every formula in the app that can't be read or that names something that doesn't exist. Those two are errors in Issues, so they stop Preview and Finish until you fix them. The other problems below, like a misspelled function or values that don't go together, show in the Formula sheet and under the boxes as you type. Every message, with an example, is in Error messages.

MessageWhat it means
There's nothing called total. Check the spelling.No variable or name is called that. Issues adds where: "There's nothing called total in “total * 2”. Check the spelling, or add it in Data & Logic."
This formula can't be read: …A typing slip, like a missing bracket or quote: "the text 'Hi needs a closing '", "it ends too early", "unexpected ')'".
There's no function called sume().The function's name is misspelled. See Formula functions.
round(number, places?) can't take 3 arguments.Too many or too few values in the brackets.
Can't use * with text and a number.The values don't go together. Use number(…) to turn text into a number.
Can't divide by zero.The number after / or % is 0. Check it first: people > 0 ? total / people : 0.
Can't read .name of a number.A dot after something that isn't a record.

The Formula sheet and the boxes under conditions work with your variables' starting values, and the Formula sheet treats it and error as empty. A formula that works there can still go wrong while the app runs, when the values are different. Then:

  • A setting linked to the formula gets no value, so it shows empty.
  • A Show when that can't be worked out shows the view.
  • An If whose condition can't be worked out fails, like any step that fails: see The debugger.

#See also