How do I use formulas?

Modified on Thu, 7 Nov at 1:24 PM

Formula Logic is a powerful tool that lets you add dynamic and automated behaviors to your forms.  By writing formulas, you can calculate values, use datasets, and evaluate conditions to control how your data behaves.  Formulas can make your forms and workflows even more automated and reduce the potential for human error.

When should I use a formula?

Formulas are essential for cases where the form needs to adapt in real-time, such as calculating totals, validating data, or displaying specific sections depending on what the user selects.  They allow you to automate processes like routing tasks to the right individuals, enforcing rules (such as making sure fields meet certain criteria), or generating custom outputs based on a combination of factors.

Essentially, a formula is your go-to tool when you want the form to do more than just collect information; it enables you to create intelligent, interactive workflows that save time and reduce errors.

Some common uses:

To Calculate
Sums, Subtotals, ratios, etc.

MORE ABOUT COMPUTED COMPONENTS ▸
To Show or Hide Parts of your Form
Show or hide based on conditions

MORE ABOUT DISPLAY LOGIC ▸
To Assign Submissions Conditionally
Automatically assigning approvers based on rules and conditions
To Check for Errors
Check that a field value meets specific criteria

MORE ABOUT VALIDATE LOGIC ▸
To Send Emails Conditionally
Determine if a notification should send based on rules and conditions

First, A Quick Word About Component IDs

You’ll often reference component IDs when creating formulas.

For example, if you have an input component that collects the number of students attending a field trip (Component ID: studentCount), you can use this ID directly in your formula.  If you're collecting staff member details in another field (staffCount), you'll use these IDs to build your logic.

Just make sure to reference them exactly as they appear!

Second, A Note About Droplet AI

Before we jump into learning how to write a formula expression, the easiest way to do it is to rely on Droplet AI for assistance!


Here's how:


1

Droplet AI can be used anywhere you can type a formula.  For example, in the Form Editor, select a component and click Validate Logic from the properties panel.

2

In the top pink bar, type the validation conditions you would like to apply to this field in plain wording, for example: "must be less than $200."

3

Press enter and await a response from Droplet AI.  Accept its recommendation by clicking the Accept icon or by pressing Done.

Formula Building Blocks

Use the following building blocks to help you write your own formulas:

Simple Math

Add (+)
Adds numbers together
Example Use
studentCount + staffCount
This adds the values of studentCount and staffCount fields.
Subtract (-)
Subtracts one number from another.
Example Use
staffCount - 1
This subtracts 1 from the value of staffCount.
Multiply (*)
Multiplies numbers.
Example Use
studentCount * 2
This doubles the value of studentCount.
Divide (/)
Divides numbers.
Example Use
studentCount / staffCount
This would return the student:staff ratio.

Comparisons

Comparison operators (or conditional operators) are your form's decision-makers! They let you check whether values meet specific criteria, helping your form react to user input with true/false logic.


equals(field1, field2)
Checks if two values are the same.

You can also use:
field1 === field2
Example Use
equals(staffCount, 5)
This checks if the value of staffCount is equal to 5.
notEquals(field1, field2)
Checks if two values are different.

You can also use:
field1 !== field2
Example Use
notEquals(studentCount, staffCount)
This checks if studentCount and staffCount are not the same.
withinRange(value, min, max)
Verifies that a value falls between a minimum and maximum range
Example Use
withinRange(studentAge, 5, 18)
This checks that the age entered is appropriate for the grade levels allowed in your district.
isGreaterThan(value, comparison)
Confirms that one number is greater than another

You can also use:
value > comparison
Example Use
isGreaterThan(fundingAmount, 1000)
Let's say you want to ensure that a funding request field only accepts amounts over $1,000. This guarantees that the requested amount meets your minimum threshold.
IsGreaterThanOrEqualTo(value, comparison)
Confirms that one number is greater than or equal to another

You can also use:
value >= comparison
Example Use
isGreaterThanOrEqualTo(qty, 10)
Suppose you want to make sure an order quantity field allows a minimum order of at least 10 units. This ensures that users can’t submit an order for fewer than the minimum allowed quantity.
isLessThan(value, comparison)
Ensures that one number is smaller than another

You can also use:
value < comparison
Example Use
isLessThan(vacationDays, 30)
Maybe you want to limit the number of vacation days an employee can request to under 30. This makes sure the user doesn’t request more than the allowed days off.
isLessThanOrEqualTo(value, comparison)
The value must be less than or equal to a specific number

You can also use:
value <= comparison
Example Use
isLessThanOrEqualTo(expenseTotal, 5000)
Perhaps you want to set a cap on an expense field so it cannot exceed $5,000. This Validate Logic makes sure the submitted expense stays within budget limits.
includes([list], value)
Checks if a value is part of a specific list

You can also use:
[list].includes(value)
Example Use
includes(['UT','NY','MA'], value)
You want to make sure the selected state is one of the allowed options for your district. This ensures that users only choose from the allowed states when filling out the form.

Of course, we'd recommend just using a dropdown, radio button, or checkbox to narrow choices like this!

Logical Operators

and(condition 1, condition 2)
Ensures that all conditions are true

You can also use:
condition 1 && condition 2
Example Use
and(checklistCompleted, completionDateEntered)
In this example, both the checklist and completion date must be filled in before the submission can proceed.
or(condition 1, condition 2)
Allows for at least one condition to be true

You can also use:
condition 1 || condition 2
Example Use
or(phoneNumberProvided, emailProvided)
You want to give users the option to enter either a contact phone number or an email address. This flexibility allows the form to accept at least a phone number or email for contact purposes, but doesn't force them to provide both.

To Use Within Other Helper Functions

isOptional()
Marks the field as not required
Note!
To make a field optional, just turn off the Required switch in the field’s properties panel. However, if you need to make a field optional based on certain conditions, you can use this helper function.
Example Use
equals(nextAction, 'Approve') ? value : isOptional()
Tricky one: this is called a ternary statement.  If you're familiar with IF statements in spreadsheets, same thing!

The first test is "Is Next Action equal to Approve?"  If so, this will require a value in the field.  Otherwise, it will make it optional.
value.length
This tells you how many characters are in a value.  For lists, it will tell you how many items are in the list.
Example Use
equals(value.length, 6)
This uses two things: the equals function (see above) and the .length method. This logic ensures that the submitter enters a value that is exactly 6 characters long in the field.

Great for ID numbers and account codes!
toCurrency(value)
Converts a number into a formatted currency string, like turning 5 into $5.00

This is especially helpful when used with other helper functions, if you need to format a number as currency.
Example Use
equals(toCurrency(value), toCurrency(total))
This is using two functions: the equals function (see above) and the toCurrency function.  This is forcing both the field value and the total value into currency format before ensuring that they are equal to each other.
fromCurrency(value)
Converts a currency string back to a number, like turning $5.00 into 5

This is especially helpful when used with other helper functions, if you need to format a currency value as a number first.
Example Use
lessThan(value, fromCurrency(budget))
This is using two functions: the lessThan function (see above) and the fromCurrency function.  This is forcing the budget value into number format before ensuring that the current field value is less than the budget value.

If-Else Operator

 condition ?  return if true  :  return if false  
Checks if an expression is true or false and returns a certain value in either case.

Also called:
ternary operator
Example Use
studentCount > 100 ? 'Large Group' : 'Small Group'
If the studentCount value is greater than 100, return the text "Large Group", otherwise return the text "Small Group"
Pro Tip!
You can nest a few If-Else statements together to create a string of different conditions.  For example:


studentCount > 100 ? 'Large Group' : studentCount > 50 ? 'Medium Group' : 'Small Group'

Other Popular Helper Functions

currentStep()
Returns the ID of the submission's current workflow step
Example Use
currentStep() === 'complete'
This statement will check if the current workflow step is "complete" and return true if it is and false if it's not.  Helpful when you only want certain things to happen on certain steps.
submittedByName()
Returns the submitter's name
Example Use
submittedByName()
Used frequently to surface the submitter's name
submittedByEmail()
Returns the submitter's email
Example Use
submittedByEmail()
Used frequently to surface the submitter's email

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article