Working with Formulas in Calculator Widget

With the Calculator widget, you can turn customers’ answers into a personalized result using a formula. Building one is easier than it may sound: this guide walks you through the formula editor, from adding fields and numbers to putting them together.

As you build your formula, you may need Functions—ready-made tools for tasks like adding up costs or rounding a price. Learn how to use them in our Guide to Calculator Functions.

In This Article

Create Your Formula

To start creating your first formula, add a new Calculation on the Build tab → ➕Add Calculation:

You can either generate a formula with AI or build one manually in the editor.

Generate a Formula with AI

The easiest way to create an accurate formula is by using the Generate with AI tool, which lets you describe complex math in natural language.

Simply click the ✨ Generate with AI button in the Formula editor → enter your prompt → click Generate:

To use the Generate with AI tool in the Formula editor, create all the necessary fields first: Adding Calculator Fields. To create the entire widget using AI, check out this guide: Easy Start with Templates and AI Calculator Generator.
See an Example: Generate a Shipping Cost Formula

In this example, we calculate shipping costs based on the package’s weight and delivery distance. We’ve already added the Weight and Distance fields, so we describe our pricing rules to the AI:

If the weight is 5 kg or less, the cost is $1 per km.
If the weight is more than 5 kg and up to 10 kg, the cost is $1.50 per km.
If the weight is more than 10 kg, the cost is $1 per kg per km.

We enter the prompt, click Generate, and test the resulting formula by changing the field values:

The generated formula applies the shipping rate based on the weight, then calculates the cost using the distance:

IF(Weight <= 5, Distance * 1, IF(Weight > 5 AND Weight <= 10, Distance * 1.5, Weight * Distance))
	

Build a Formula in the Editor

You can build your formula in the Formula editor using Fields, Calculations, Functions, mathematical operators, and numbers. Each part is color-coded to help you read your formula:

Always select Fields and Calculations from the editor’s dropdowns. Typing their names manually won’t work, even if the spelling is correct.
1

Fields use the values customers enter or select in your form. Select a field from the dropdown to add it to your formula. Fields appear in purple:

For details on setting up your form, see Adding Calculator Fields. To use their values, see Use Form Fields in Your Formula.
2

Calculations let you use the result of another calculation in your formula. Select one from the dropdown to add it. Calculations appear in green:

For details on creating a calculation, see Adding Calculations. To use its result in a different formula, see Reuse a Calculation in Another Formula.
3

Functions are ready-made tools for tasks like rounding a price or applying discounts. Select one from the dropdown. Function names, brackets, and commas appear in white:

Find the right function and see how to use it in our Guide to Calculator Functions.
4

Mathematical operators let you add, subtract, multiply, divide, and raise numbers to a power. These operators and round brackets are available as buttons in the bottom row and appear in white:

The editor calculates brackets first, then powers, multiplication and division, and finally addition and subtraction. For example, 1 + 2 * 3 = 7, while (1 + 2) * 3 = 9.

5

Numbers can be typed directly into the editor and appear in orange: You can also enter decimals, such as 0.01, and percentages, such as 1%.

Common Errors

The widget automatically checks your formula when you click outside the Formula editor. If it finds an issue, an error message appears:

Open the matching error below to see what may cause it and how to fix it.

Invalid Formula

This error can happen for three reasons:

  1. Incorrect formula syntax. Check for missing brackets, commas, or other typing mistakes:
  2. An error in another Calculation. If your formula uses a calculation that contains an error, open that calculation and fix its formula first:
  3. A Field or Calculation name typed manually. The editor won’t recognize a name entered from your keyboard. Delete it and select the field or calculation from the dropdown instead:
Deleted Value
Your formula uses a Field or Calculation that has been deleted. Remove it from the formula or select a replacement from the dropdown:

Now, let's take a closer look at the Field component.

Use Form Fields in Your Formula

When you add a Field to your formula, it uses the customer’s answer from that field. As the customer changes their answer, the result updates dynamically:

You can use Fields in both simple math and functions—for example, to add two field values together or find the largest value. Here's an example that uses the Number field:

Most fields provide one value at a time, such as a number, text, or a date. However, Choice and Image Choice fields can provide several values when Multiple Selection is enabled—one for each selected option:

To use these fields in a formula, you need to tell it how to handle the selected values—for example, by adding them together. In the next section, we'll dive deeper into this.

Work with Multiple Selections

When Multiple Selection is enabled for a Choice or Image Choice field, the field holds a list of selected values instead of just one number.

As an example, let’s look at a Choice field with three options, valued at 1, 2, and 3. In the formula below, nothing is selected, so the result is 0:

When several options are selected, the same formula cannot calculate a result because the field now contains several numbers:

Before adding this field to a mathematical operation, choose a function that tells the formula how to handle the selected values. Here are four options:

  • SUM(Choice) — Adds up all selected values.
  • MAX(Choice) — Returns the largest selected value.
  • MIN(Choice) — Returns the smallest selected value.
  • CONTAINS(Choice, X) — Checks whether the value X is among the selected values.
In these formulas, Choice is the name of your field. For more details and examples, see our Guide to Calculator Functions.

Let’s use a shipping cost calculator to show how these functions work. The base shipping cost is calculated as Weight * 2, because the rate is $2 per kg. Product Type is a Choice field with Multiple Selection enabled. Each option has a numeric value (Standard = 0, Fragile = 10, Perishable = 5, and Hazardous = 15):

Open an example below to see a simple formula, followed by how to apply it to this shipping calculator:

Use SUM to add up selected values

SUM adds up the selected values:

SUM(Choice)

In this simple example, options 2 and 4 are selected, so the result is 6. If nothing is selected, the result is 0:

In the shipping calculator: Add the selected product type fees to the base price. For example, Fragile and Perishable add $15:

(Weight * 2) + SUM(Product Type)
	

Use SUM to check whether anything is selected

Use SUM to add up the selected values and IF to check whether the total is greater than zero:

IF(SUM(Choice Field) > 0, value if true, value if false)

Here, Option 1 has a value of 1 and is selected, so the result is Something is selected. If nothing is selected, the result is Nothing is selected:

This check assumes every option has a value above zero. An option valued at 0 won’t increase the total, and negative values can cancel out positive ones.

In the shipping calculator: Add one $10 fee if any special product type is selected. Rename the field to Special Product Type and remove the Standard option so that all remaining values are positive:

(Weight * 2) + IF(SUM(Special Product Type) > 0, 10, 0)
	

The fee stays $10 whether the customer selects one special product type or several.

Use CONTAINS to check for a specific option

Use CONTAINS with IF to change the result depending on whether a particular value is selected:

IF(CONTAINS(Choice Field, value to check), value if true, value if false)

Here, we check the Choice field for the value 2. Option 2 is selected, so the result is Option 2 is selected. Otherwise, it would be Option 2 is not selected. This works even when other options are selected too:

In the shipping calculator: Increase the base price by 25% if hazardous products are included. CONTAINS checks for the Hazardous option’s value, 15. IF applies a multiplier of 1.25 when it is selected, or 1 otherwise:

(Weight * 2) * IF(CONTAINS(Product Type, 15), 1.25, 1)
	

Reuse a Calculation in Another Formula

If your formula becomes long or complex, you can break it into smaller parts. To do this, create a separate Calculation by going to the Build tab and clicking ➕Add Calculation:

You can then use its result in another formula by selecting it from the Calculation dropdown.

In this example, Principal Amount is a field, and Total Amount Receivable is another calculation. We subtract the field’s value from that calculation’s result to find the interest earned:

See an Example: Create a Deposit Calculator

In this example, customers enter a deposit amount and a term in years. The widget shows the total they’ll receive at the end of the term and the interest earned:

We use two Slider fields—Principal Amount and Term in years—and create two calculations:

1

Calculate the total amount. Create a calculation named Total Amount Receivable. The formula below adds simple interest at 2% per year to the initial deposit:

Principal Amount * (1 + 0.02 * Term in years)

2

Calculate the interest earned. Create another calculation named Interest Receivable. Select Total Amount Receivable from the Calculation dropdown, then subtract the Principal Amount field:

Total Amount Receivable - Principal Amount

The second calculation reuses the first result, so you only need to write—and update—the interest formula once.


You’re now ready to put together a formula for your calculator! For help choosing the right functions, explore our Guide to Calculator Functions, with explanations and examples.

Still need a hand? Contact our Support Team—we’ll be happy to help!

Did this article answer your question? Share your feedback: Thanks for sharing your feedback. It helps us grow! There was a problem submitting your feedback. Please try again later.

Still looking for assistance? Contact Us Contact Us