PadCodedocs

Formula language reference

Everything formulas can do, with an example of each: values, names, operators, functions, text with braces, dates, and every error message.

A formula is a short expression that works a value out, like total * (1 + tip) / people. PadCode's formulas are written much like Swift: numbers, text in quotes, names, operators, and functions with their values in brackets. This page covers all of it. For a gentler start, see Formulas.

The Formula sheet: a box to type in, the app's data to tap, and the How formulas work card.

#The sample data

Every example on this page, and on Formula functions, uses these variables. Picture them in Data & Logic, with these starting values:

NameTypeValue
totalDecimal Number120
tipDecimal Number0.25
peopleWhole Number3
nameTextSam
nicknameTextempty: nothing typed yet
qtyTextText3, typed into a Text Field (so it's text, not a number)
couponAnythingnull: no value at all
isMemberTrue / Falsetrue
scoresList of Whole Numbers70, 95, 82, 95
tasksList of Recordsthree tasks, each with a title and a True / False done: Call Sam (done), Buy milk (not done), Pay rent (not done)
itemsList of Recordstwo invoice lines, each with a qty and a rate: 1 × 1200 and 4 × 85
userRecordname Ada, age 36, and address, a record with city London
startDateDate & Time2:30 PM UTC on October 28, 2026, stored as 2026-10-28T14:30:00Z

#How to read the results

The Result column writes each answer the way you'd write that value in a formula, so you can tell its kind:

  • Numbers as they print: 4, 3.5, -2. A whole number never shows .0.
  • Text in double quotes, so you can see spaces and tell "5" from 5. In your app, text shows without the quotes.
  • true, false and null as they are.
  • Lists in square brackets: [70, 82]. In text, a list prints as its items with commas between them.
  • A record the way it prints in text: {"city":"London"}.
  • Error: and the message, when the formula can't give an answer.

Money, percentages, dates and times depend on the iPad's language, region and time zone. On this page they're shown for an iPad set to English (US), in New York time. In late October 2026, New York is 4 hours behind UTC; from November 1 it's 5 hours behind.

#Where you write formulas

WhereHowWhat it should give
A setting in the Style tab, or in a step's settingsTap ⚡︎ beside it and choose Formula….A value the setting can use: a number for a size, text for a title, a list for a Repeater's data.
Show when, in the Style tab's Show & enableType in the box.True or false: the view shows while it's true.
An If's Condition, and the Where of Update in List and Remove from ListType in the box, or tap the ƒ button beside it to open the Formula sheet.True or false. In Where, it is each item of the list.
Text: a Text's Content, a Button's Title, a step's Text and other settings you type words intoPut a formula in braces: Hi, {name}.Anything: it's printed into the text. See Text with braces.

The Formula sheet shows the answer as you type, in green: Right now: and the result, worked out with your variables' starting values. When the answer prints as nothing, like empty text or null, it says Right now: (empty). A formula can be up to 2,000 characters long.

#Values

Values are what formulas work with. You can write numbers, text, true and false, null and lists straight into a formula. Records come from your variables, list items and APIs.

#Numbers

Write digits, with a dot for decimals: 12, 3.5, 0.25. Put a minus in front for a negative number. Any number can have decimals, so 7 / 2 is 3.5, and a whole number prints without a dot: 1.0 prints as 1.

FormulaResult
4242
3.503.5
1.01
-7-7
7 / 23.5
0.1 + 0.20.30000000000000004
power(10, 16)1e+16
.5Error: This formula can't be read: unexpected '.'.
+5Error: This formula can't be read: unexpected '+'.
1,000Error: This formula can't be read: unexpected ','.
1e3Error: This formula can't be read: unexpected 'e3'.
  • Write 0.5, not .5, and leave out thousands separators and a leading +.
  • Some decimals can't be stored exactly, so 0.1 + 0.2 prints a long tail. Use round(x, 2) to compare or keep a tidy number, and fixed, currency or percent to show one.
  • Numbers of a million billion (1,000,000,000,000,000) or more print differently: power(10, 15) gives 1000000000000000.0, and bigger ones print like 1e+16.

#Text

Put text in straight quotes, single or double: 'Hello' or "Hello". To put a quote inside, use the other kind around it, or type a backslash before it. A backslash keeps the next character as it is, so there are no codes like \n for a new line: \n is the letter n.

FormulaResult
'Sam'"Sam"
"Sam""Sam"
"It's""It's"
'It\'s'"It's"
'C:\\files'"C:\files"
'one\ntwo'"onentwo"
''""
‘Sam’Error: This formula can't be read: can't read '‘Sam’'.
'SamError: This formula can't be read: the text 'Sam needs a closing '.

Curly quotes (‘ ’ and “ ”) aren't quotes to a formula: use the straight ones, ' and ".

#True, false and null

true and false are the two answers a condition gives. null means no value at all: a variable of type Anything that's empty, a field a record doesn't have, or an API value that hasn't loaded. Empty text isn't null: it's text with nothing in it.

FormulaResult
truetrue
falsefalse
nullnull
couponnull
nickname""
nickname == nullfalse

#Lists

Write a list in square brackets, with commas between the items. Items can be any values, other lists included, and any formulas.

FormulaResult
[1, 2, 3][1, 2, 3]
['a', total, [true, null]]["a", 120, [true, null]]
[][]
[1, 2,]Error: This formula can't be read: unexpected ']'.

#Records

A record holds named fields, like user's name and age. Formulas read records and their fields, but can't write a new one: braces in a formula are an error. Make records with variables of type Record, let an API or a list give them to you, or read them from JSON text with parseJSON. keys and values list a record's fields.

FormulaResult
user.address{"city":"London"}
{city: 'Paris'}Error: This formula can't be read: can't read '{city: 'Pari'.

The error shows up to 12 characters of what it couldn't read.

#Names

A name reads a value: one of your variables, or one of the special names below. Names start with a letter or _, then use letters, numbers and _. They match exactly, capital letters included.

FormulaResult
total120
TotalError: There's nothing called Total. Check the spelling.
totl * 2Error: There's nothing called totl. Check the spelling.

true, false and null always mean those values, so a variable with one of those names can't be read by a formula.

#Reading inside a value

Add .field to read a record's field, and [number] to read a list's item. The first item is [0]. You can also read a field by its name in quotes, ['field'], which works for any field name, even one with spaces. Mix them as deep as you need. Anything inside the square brackets can be a formula.

FormulaResult
user.name"Ada"
user.address.city"London"
user['name']"Ada"
scores[0]70
scores[people - 2]95
tasks[1].title"Buy milk"
tasks[0]['done']true

A field that isn't there gives null, and so does an item past either end of the list. So does reading anything from null, however deep: if coupon is null, coupon.code is null too. That's why ?? works well after a path: user.phone ?? 'No phone'.

FormulaResult
user.phonenull
user.address.zip.codenull
scores[10]null
scores[-1]null
scores[1.5]null
coupon.codenull
tasks.titleError: Can't read .title of a list.
name.countError: Can't read .count of text.
scores['0']Error: Can't read [0] of a list.
user[0]Error: Can't read [0] of an object.
scores.0Error: This formula can't be read: expected a name after '.'.
  • A dot only reads a record's field. To get a field from every item of a list, use map(tasks, it.title).
  • Text and lists have no fields: use functions instead, like count(name).
  • A list's item number must be a whole number, and a record's field name must be text. Messages call a record "an object".

#Special names

Besides your variables, formulas know these names. params and theme exist everywhere; the others only in some places.

NameWhat it isWhere it exists
paramsThe values a screen was opened with: its Screen inputs, like params.id. Inside a reusable action's steps, the inputs that action was run with.On every screen and in every step. An input the screen doesn't have gives null.
itemThe current item.In the views inside a Repeater or a Tree, and in the steps those views run.
itEach item of a list, in turn.Inside filter, find, map, sort, any and all. In the steps of Repeat for Each. In Update in List's Where and With, and Remove from List's Where.
errorWhat went wrong: error.message says it in words. When a Call API got an error answer, error.status is its status code and error.body the server's answer.In a Try's Catch steps.
eventWhat a trigger hands its steps. When a Value Changes: event.oldValue and event.newValue. When Hovered: true as the pointer arrives, false as it leaves. When Dragging Starts or Stops: true as the knob is grabbed, false as it's let go. When Apple Pencil Is Squeezed: event.phase, which is 'began', 'changed' or 'ended'. A Location Button's steps: event.latitude, event.longitude and event.accuracy (in meters).In the steps of those triggers.
pastedThe text that was pasted.In a Paste Button's steps.
themeYour Asset Colors, by name. A color added in Assets is a record with a light and a dark version, so theme.brand.light is text like '#5B6CFF'.Everywhere.

Outside its place, one of these names gives "There's nothing called …" when the formula runs. Inside filter, find, map, sort, any and all, it means that function's item, even inside Repeat for Each's steps, and inside a map within a map, it is the inner item.

A variable with one of these names gets in the way: a variable called params, item or theme hides the special name, and it, error, event and pasted hide a variable with their name. Give your variables other names.

#Operators

OperatorNameWith numbersWith textWith other values
+Add, or joinAdds.Joins: if either side is text, the other side is printed as text and the two are joined.An error, unless the other side is text.
- *Subtract, multiplySubtracts, multiplies.An error.An error.
/DivideDivides, keeping decimals. Dividing by 0 is an error.An error.An error.
%RemainderWhat's left after dividing. Works with decimals too, and takes the sign of the left side. By 0 is an error.An error.An error.
- in frontMinusFlips the sign.An error.An error.
== !=Equal, not equalEqual when they're the same number: 1 == 1.0.Equal when every character matches, capital letters included.Lists are equal when their items are equal, in order. Records are equal when they have the same fields with equal values. Values of different kinds are never equal: the number 3 and the text '3' aren't.
< <= > >=Less, at most, more, at leastBy size.Character by character, by their code: capital letters come before lowercase ones, and '10' comes before '9'. Dates written the same way compare by time.An error, and so is comparing a number with text.

The logic operators work with any kind of value:

OperatorNameWhat it does
&&Andtrue when both sides are true. If the left side is false, the right side isn't worked out.
||Ortrue when at least one side is true. If the left side is true, the right side isn't worked out.
!NotFlips true and false.
??FallbackThe left side, unless it's null: then the right side. Only null counts; empty text, 0 and false don't.
? :Choicecondition ? a : b gives a when the condition is true, b when it's false. Only the side it picks is worked out.

#Math

FormulaResult
2 + 35
total - 20100
total * tip30
total / people40
total / 0Error: Can't divide by zero.
7 % 31
7.5 % 21.5
-7 % 3-1
5 % 0Error: Can't divide by zero.
-total-120
5 - -38
-nameError: Can't use - with text.

#Joining text with +

FormulaResult
'Hi, ' + name"Hi, Sam"
'Total: ' + total"Total: 120"
qtyText + 1"31"
number(qtyText) + 14
1 + 2 + ' apples'"3 apples"
'apples: ' + 1 + 2"apples: 12"
'Scores: ' + scores"Scores: 70, 95, 82, 95"
'Coupon: ' + coupon"Coupon: "
qtyText * 2Error: Can't use * with text and a number.
coupon + 1Error: Can't use + with null and a number.
isMember + 1Error: Can't use + with true or false and a number.
[1, 2] + [3]Error: Can't use + with a list and a list.

+ works left to right, so 1 + 2 + ' apples' adds first, then joins, while 'apples: ' + 1 + 2 joins twice. What people type in a Text Field is text, so turn it into a number with number(…) before doing math with it.

#Comparing

FormulaResult
total > 100true
total != 100true
1 == 1.0true
qtyText == 3false
'Sam' == 'sam'false
[1, 2] == [1, 2]true
[1, 2] == [2, 1]false
find(tasks, it.done) == tasks[0]true
coupon == nulltrue
0.1 + 0.2 == 0.3false
round(0.1 + 0.2, 2) == 0.3true
'apple' < 'banana'true
'Zoe' < 'adam'true
'10' < '9'true
startDate < '2026-11-01'true
total > '100'Error: Can't use > with a number and text.
coupon > 5Error: Can't use > with null and a number.
1 < 2 < 3Error: Can't use < with true or false and a number.
  • == never turns one kind into another. To compare typed text with a number, use number(qtyText) == 3.
  • To compare text without caring about capital letters, use lowercase(…) on both sides.
  • To check a value is between two others, use &&: total >= 100 && total <= 200.
  • A null can't be compared with < or >. Give it a fallback first: (coupon ?? 0) > 5.

#What counts as true

Conditions, !, &&, || and ? : accept any value. false, null, 0, empty text and an empty list count as false. Everything else counts as true, including the text 'false', the text '0', a space, and a record with no fields.

FormulaResult
isMember && total > 100true
!nicknametrue
!scoresfalse
!0true
!'false'false
nickname || nametrue
0 || ''false
isMember || 1 / 0true
false && 1 / 0false

&&, || and ! always give true or false, never one of the values, so nickname || name is true, not "Sam". To pick a value, use ? : or ??.

#Fallbacks with ?? and choices with ? :

FormulaResult
coupon ?? 'none'"none"
user.phone ?? 'No phone'"No phone"
nickname ?? 'Guest'""
nickname ? nickname : 'Guest'"Guest"
0 ?? 50
missing ?? 0Error: There's nothing called missing. Check the spelling.
people > 0 ? total / people : 040
isMember ? 'Member' : 'Guest'"Member"
false ? 1 / 0 : 'safe'"safe"
total > 100 ? 'Big' : total > 50 ? 'Medium' : 'Small'"Big"
  • ?? only replaces null. A Text variable starts as empty text, not null, so for text use nickname ? nickname : 'Guest' or isEmpty(nickname) ? 'Guest' : nickname.
  • ?? doesn't fix a misspelled name: a name that doesn't exist is an error before ?? gets a look.
  • ? : works out only the side it picks, so people > 0 ? total / people : 0 never divides by zero.

#Which part is worked out first

When a formula has several operators, the ones higher in this table are worked out first. Operators on the same row go left to right, except the ones in front of a value and ? :, which group from the right. Brackets ( ) always go first: add them whenever you're not sure.

OrderOperatorsGroups
1.field, [item], function calls f(…)Left to right
2! and - in front of a valueRight to left: !!x, - -3
3* / %Left to right
4+ -Left to right
5== != < <= > >=Left to right
6&&Left to right
7||Left to right
8??Left to right
9? :Right to left
FormulaResult
1 + 2 * 37
(1 + 2) * 39
10 - 4 - 33
-2 * 3 + 7 % 4-3
!true == falsetrue
true || false && falsetrue
user.age ?? 0 > 5036
(user.age ?? 0) > 50false
'Status: ' + isMember ? 'member' : 'guest'"member"
'Status: ' + (isMember ? 'member' : 'guest')"Status: member"
true ? 1 : false ? 2 : 31

Two of these catch people out:

  • ?? comes after the comparisons, so user.age ?? 0 > 50 means user.age ?? (0 > 50). Put the fallback in brackets: (user.age ?? 0) > 50.
  • ? : comes last, so everything before the ? is the condition. In 'Status: ' + isMember ? 'member' : 'guest', the condition is the text "Status: true". Put the choice in brackets.

#Functions

A function does a job on the values you give it: write its name, then the values in brackets, separated by commas: round(total / 7, 2). Function names match exactly, capital letters included. Functions go inside each other, and the inner one is worked out first.

  • Some values can be left out: on Formula functions, they end in ?, like round(number, places?).
  • min and max take as many numbers as you like, or one list.
  • filter, find, map, sort, any and all work out their second value once for each item of the list, with it as that item: filter(tasks, !it.done). A function inside, like contains, can use it too.
FormulaResult
round(total / 7, 2)17.14
round(total / 7)17
max(4, 9, 2)9
count(filter(tasks, !it.done))2
map(filter(tasks, !it.done), it.title)["Buy milk", "Pay rent"]
map([[1, 2], [3]], sum(map(it, it * 10)))[30, 30]
Round(2.5)Error: There's no function called Round().
total(2)Error: There's no function called total().
round(1, 2, 3)Error: round(number, places?) can't take 3 arguments.
now(1)Error: now() can't take 1 argument.
round(qtyText)Error: round needs a number, not text.

Values a function reads as text take anything and use it as it prints, so uppercase(5) is fine. Values it reads as numbers must be numbers. Every function, with what it takes and examples, is on Formula functions.

#Text with braces

In any setting you type words into, put a formula in braces and the text shows its answer: Each pays {total / people}. The canvas shows it with your starting values, and Preview with the live ones. See Text with values for where it works.

Each kind of value prints like this:

KindPrints as
A whole numberWithout .0: 40
A decimal numberEvery digit it has: 17.142857142857142. Use round, fixed, currency or percent to show fewer.
TextAs it is, without quotes
true, falsetrue, false
nullNothing
A listIts items with a comma and a space between them
A recordIts fields in braces and quotes, sorted by name, the way APIs send them
A dateThe text it's stored as, like 2026-10-28T14:30:00Z: use formatDate to show it for people
TextShows
Hello, {name}!Hello, Sam!
Each pays {total / people}Each pays 40
{total / 7}17.142857142857142
{round(total / 7, 2)}17.14
Member: {isMember}Member: true
[{coupon}][]
Scores: {scores}Scores: 70, 95, 82, 95
{user}{"address":{"city":"London"},"age":36,"name":"Ada"}
Starts {startDate}Starts 2026-10-28T14:30:00Z
Starts {formatDate(startDate)}Starts Oct 28, 2026
{'Say "hi"'}Say "hi"
{{name}} is {name}{name} is Sam
{{{name}}}{Sam}
Open { all dayOpen { all day
Price: {total} }Price: 120 }
Hi {nmae}Error: There's nothing called nmae. Check the spelling.
Hi {}Error: This formula can't be read: it's empty.
{first name}Error: This formula can't be read: unexpected 'name'.
{'a}b'}Error: This formula can't be read: the text 'a needs a closing '.
  • To show a brace itself, type two: {{ shows {, and }} shows }.
  • A { with no } after it, before the next {, shows as it is. So does a } on its own.
  • The formula ends at the first }, so it can't contain braces, even in quotes.
  • When any formula in the text can't be worked out, the whole text shows as you typed it, braces and all. Issues lists braces that can't be read or that name something that doesn't exist.

#Dates and times

Formulas keep dates as text in the ISO 8601 form: '2026-10-28T14:30:00Z' is 2:30 PM on October 28, 2026, in UTC (the Z). A Date & Time variable and a Date Picker store dates this way.

The date functions read:

  • A date and time in UTC, ending in Z: '2026-10-28T14:30:00Z'. Fractions of a second are fine, and dropped.
  • A date and time with an offset from UTC, like '2026-10-28T16:30:00+02:00'.
  • A day on its own: '2026-10-28' means midnight at the start of that day in the iPad's time zone.

now(), today(), date(…), addDays, addMonths, addMinutes and startOf give back a date and time in UTC, ending in Z, to the second. date(…) also reads a number of seconds since 1970, as many web APIs send dates. formatDate turns one into words for people, in the iPad's language and time zone.

FormulaResult
startDate"2026-10-28T14:30:00Z"
date('2026-10-28')"2026-10-28T04:00:00Z"
date('2026-10-28T16:30:00+02:00')"2026-10-28T14:30:00Z"
date('2026-10-28T14:30:00.250Z')"2026-10-28T14:30:00Z"
date('10/28/2026')null
date('2026-10-28T16:30:00+02:00') == startDatetrue
startDate < '2026-11-01'true
addDays(startDate, 1)"2026-10-29T14:30:00Z"
addDays(startDate, 7)"2026-11-04T15:30:00Z"
addMinutes(startDate, 90)"2026-10-28T16:00:00Z"
daysBetween('2026-10-28', '2026-11-02')5
formatDate(startDate)"Oct 28, 2026"
formatDate(startDate, 'time')"10:30 AM"
formatDate('2026-10-28T02:00:00Z')"Oct 27, 2026"
  • Comparing dates. <, > and == compare dates as text, which puts them in time order when they're written the same way. To compare dates written differently, pass both through date(…) first.
  • Time zones. A date in UTC can fall on another day where the iPad is: 2 AM UTC on October 28 is still October 27 in New York. formatDate and daysBetween use the iPad's time zone, and so do today() and plain days like '2026-10-28'.
  • Days and minutes. addDays keeps the time on the iPad's clock, so across a change to or from daylight saving time, the UTC time moves by an hour: in New York, a week after 10:30 AM on October 28 is 10:30 AM on November 4, which is 15:30 UTC. addMinutes always adds exact minutes.
  • In text, a date prints as it's stored. Use {formatDate(startDate)} to show it for people.

Date functions: now, today, date, timestamp, addDays, addMonths, addMinutes, startOf, daysBetween and the other …Between functions, the parts of a date (hour, minute, second, day, month, year, weekday), formatDate and formatDuration. sort puts dates in time order when they're written the same way.

#Error messages

When a formula can't give an answer, you see one of these messages. In the messages, "an object" is a record.

#Formulas that can't be read

These start with "This formula can't be read:", then what PadCode tripped on.

FormulaResultWhat to do
Error: This formula can't be read: it's empty.The formula is blank, like a condition box with only spaces, or {} in text. Type a formula there, or remove the blank one.
total +Error: This formula can't be read: it ends too early.Finish the formula: something is missing after an operator.
round(totalError: This formula can't be read: it ends too early, expected ')'.Add the closing bracket, square bracket or : it names.
isMember ? 'Yes'Error: This formula can't be read: it ends too early, expected ':'.A ? needs a : and a value for when the condition is false.
round(total 2)Error: This formula can't be read: expected ')', found '2'.Something is missing before what it found, often a comma.
people > 0 ? 1, 2Error: This formula can't be read: expected ':', found ','.Use : between the two choices.
total peopleError: This formula can't be read: unexpected 'people'.Two values sit side by side: add an operator or a comma between them, or remove one.
total = 5Error: This formula can't be read: can't read '= 5'.A character formulas don't use. To compare, write ==.
#tagError: This formula can't be read: can't read '#tag'.Put words in quotes: '#tag'.
'SamError: This formula can't be read: the text 'Sam needs a closing '.Add the closing quote.
scores.0Error: This formula can't be read: expected a name after '.'.Read list items with square brackets: scores[0].
name.uppercased()Error: This formula can't be read: unexpected '('.Formulas have no methods: use a function, uppercase(name).

#Names and functions

FormulaResultWhat to do
totl * 2Error: There's nothing called totl. Check the spelling.Fix the spelling and capitals, add the variable in Data & Logic, or check you're in a place where that special name exists.
sume(scores)Error: There's no function called sume().Fix the name: see Formula functions.
round(1, 2, 3)Error: round(number, places?) can't take 3 arguments.The message shows what the function takes. Add or remove values.

#Values that don't go together

FormulaResultWhat to do
qtyText * 2Error: Can't use * with text and a number.Turn text into a number first: number(qtyText) * 2.
-nameError: Can't use - with text.A minus in front only works on numbers.
total / 0Error: Can't divide by zero.Check first: people > 0 ? total / people : 0.
tasks.titleError: Can't read .title of a list.Use map(tasks, it.title), or pick an item: tasks[0].title.
user[0]Error: Can't read [0] of an object.Read a record's field by name: user['name'].
round(qtyText)Error: round needs a number, not text.Give the function the kind of value it takes.
first(coupon)Error: first needs a list, not null.Give a fallback list: first(coupon ?? []).
min(scores, 50)Error: min needs numbers, not a list.Give numbers or one list, not both.
count(total)Error: count needs a list or text, not a number.Count a list, text or a record.
addDays('soon', 1)Error: addDays needs a date like '2026-10-28', not 'soon'.Give a date in the form on Dates and times.
addDays(startDate, power(10, 20))Error: addDays needs a whole number of days.Give a number of days that isn't huge.
random(6, 1)Error: random needs two whole numbers, the lowest first.Put the lowest first, with at least one whole number between them.
range(1, 20000)Error: range can make at most 10,000 numbers.Use a smaller range.
formatDate(startDate, 'full')Error: formatDate's style is short, medium, long, time, relative, weekday, month or a pattern like 'HH:mm', not full.Use one of those styles.

#Where you see them

WhereWhat it shows
The Formula sheetAny message, in orange under the box, as you type. It works the formula out with your starting values.
Under Show when, and under an If's Condition or a WhereAny message, in orange under the box.
IssuesOnly formulas that can't be read, and names that don't exist. Both are errors, which stop Preview and Finish until you fix them. Issues says where: "“count +”: This formula can't be read: it ends too early." and "There's nothing called totl in “totl * 2”. Check the spelling, or add it in Data & Logic." It doesn't run formulas, so the other messages don't show there.
While the app runsA formula can work with your starting values and still go wrong with live ones. Then a setting linked to it gets no value and shows empty; a Show when shows the view; text with braces shows as you typed it; and an If, Update in List or Remove from List whose formula can't be worked out fails, like any step that fails: the debugger and the red message at the top of the app say why, in the words above, and inside a Try, error.message holds them.

#What formulas can't do

A formula works out one value from others. It can't change anything, so some jobs belong to actions instead:

  • No assignment. total = 5 is an error. To change a variable, use a Set Value step.
  • No loops. Use filter, map, find, sort, sum and count on a list, or a Repeat for Each step to run steps for each item.
  • No functions of your own, and no names of your own inside a formula. Put steps you reuse in a reusable action, and keep in-between values in variables.
  • No new records. {…} in a formula is an error. parseJSON('{"a": 1}') reads one from text.
  • No methods. name.count and name.uppercased() don't work: use count(name) and uppercase(name).

#If you know Swift

Formulas look like Swift expressions, with a few differences:

  • Text can use single or double quotes, and + joins text with anything: 'Total: ' + total.
  • There's one kind of number. 7 / 2 is 3.5, and % works with decimals.
  • There's no string interpolation inside a formula: join with +, or use braces in text.
  • Optional chaining is built in and there's no ?.: user.address.city is null when any part is missing.
  • ?? is looser than comparisons, unlike Swift: a ?? 0 > 5 means a ?? (0 > 5).
  • !, &&, || and conditions take any value and use what counts as true.
  • Comparisons don't chain: 1 < 2 < 3 compares true with 3, which is an error.
  • No let, closures, methods, or ===. Functions are free-standing and lowercase-first, like uppercase(name): slice(name, 0, 2), not name.prefix(2), and reverse(scores), not scores.reversed().
  • Angles are in degrees, not radians: sin(90) is 1.

#See also