Skip to main content

How to use a variable with a formula

Use formula variables to perform calculations automatically, whether for an area calculator, a donation form, quiz scoring, or a BMI test.

Updated today

Variables act like invisible containers that accumulate or calculate values while a user interacts with your form:

  • You can set up logic to “drop” values into these containers based on what the user selects, types, or does.

  • You can also use formula-type variables to perform mathematical calculations and even use values from other form fields or variables.

💡 To learn more about variable types and general use cases, check out this article on what variables are, why & how to use them

When should you use a formula variable?

Formula variables let you perform real-time calculations in your form using custom formulas and values from other fields or variables. They're ideal when:

  • You need to calculate mathematical, physical, or other values using inputs from numeric fields (e.g., multiply length by width to calculate area m²)

  • You want to run a calculation using values of other Integer/Decimal variables: estimate the total price by summing up multiple services' costs (e.g., service1_cost + service2_cost), or calculate the score % of the max score (e.g., total_score/15*100)

  • You want to calculate the total (e.g., in a quiz using NPS fields, with question scoring from 1 to 10)

How to add a formula variable to your form

You can manage all your variables in the Variables section of the Form Editor, and access each variable's settings upon clicking on it and turning to the right-hand panel.

Here's how you can add a new Formula variable to your form:

  1. Navigate to the Variables section, click +Add to add a new variable, and select Formula

  2. Give it an ID (to use the variable value in further calculations, or to display the calculated value elsewhere in the form)

  3. Give it a title (to easily tell one variable from the other in Logic)

How to set up a formula for your variable

When you create a formula-type variable, you'll see a field called Default formula in its settings panel. This is where you enter the formula that calculates the variable's value:

A few key things to keep in mind:

1. You can use the values from other fields and variables in formulas

  • Pull values from other form fields that hold numeric values (e.g., a Number field or an NPS score field)

  • Use values from other variables for layered calculations (Integer or Decimal)

To pull the value of another variable or field into a formula, use its ID (without an @), for instance:

width*length*55

(width and length are IDs of Number fields, 55 is the static price in $ per m²)

seo_service*0.90+marketing_service*0.75

(seo_service and marketing_service are IDs of Integer variables, 0.90 and 0.75 are coefficients to apply a 10% and a 25% discount to each corresponding service)

2. Parentheses () are not supported in formulas

Still, in most cases, you can either use multiple variables to layer the calculations or restructure your formula in a way that doesn't require using parentheses.

Option 1 – Use separate variables, and layer the calculations:

Let's say you want to calculate a total score as a % of the maximum score, while your total score is a sum of several fields.

Instead of using a formula like (question1+question2+question3)/30*100, create two separate variables – to first calculate the total score, and then calculate the score % of the max score:

  • total_score = question1+question2+question3

  • score_percent = total_score/30*100

Option 2 – Flatten the formula by distributing multiplication, if possible:

Let's say you want to calculate the total cost of multiple services for a 3-month term. Instead of using a formula like (service_1+service_2)*3, get rid of parentheses by adding the multiplier next to each service:

  • total_cost = service_1*3+service_2*3

How to display variable values in your form and follow-ups

Use answer piping to personalize your messages and follow-ups; show dynamically-calculated values to respondents based on their input.

Make sure you assigned an ID to the variable, then use an @ (at-sign) and variable ID to pipe the variable's value elsewhere:

For example:

  • Total price of the selected services is $@total_price.

  • You scored @final_score points out of 150!

  • Based on your answers, you are @introvert_score_percent% introverted.

You can dynamically display the variables' values:

  • in other fields' titles and descriptions,

  • on the ending pages,

  • in custom email templates:

💡 A use case example: calculate floor area and estimate total cost

Let’s build a form that calculates the floor area of a room and estimates the cost of flooring installation based on floor area & cost/m².

Step 1: Create a new form
Go to your Formaloo dashboard and click + New > Form to start from scratch.

Step 2: Add number fields for room dimensions

Add a number field called Room width and set its field ID to room_width.
Then add another number field called Room length with the field ID room_length.

Step 3: Add a formula variable to calculate the area
Create a formula-type variable with the ID room_area.
In the Default formula field, use the formula: room_width*room_length.

Step 4: Add another formula variable to calculate the price
Create a second formula variable with the ID price_estimate.
Set the Default formula to: room_area*55 (where $55 is an imaginary price per m²).

Step 5: Display the quote to the person filling out the form
Add a content block at the end of the form. Pipe your variable values by using @s + variable IDs in your message:

Your room floor area: @room_area m²,

Price per m2: $55,

The estimated total price for the job is $@price_estimate.

And the quote will be dynamically calculated and shown to the respondent based on their input:

Explore other examples of using variables in our tutorials:

A donation form that uses a variable to calculate and display the payable amount of the donation.

An online personality quiz that compares the scores of your variables with logic and picks the relevant personality type based on your responses.

A BMI test with logic and calculations, using variables to calculate the BMI value based on the person's input.

Did this answer your question?