## Overview

Formula field enables you to perform mathematical calculations in the email. You can create a formula which will calculate and display an output based on the email recipient’s response(s) to questions in a form.

Here are some examples of how you can use formula field to drive engagement and conversion:

## Creating a personality quiz

Personality quizzes function by categorizing individuals into distinct personality types based on their responses to a series of questions about themselves. Depending on the choices made by the individual, they are grouped into one of the quiz results, which correspond to specific personality types. You can use these quizzes for lead generation.

Here is an example of a personality quiz to identify what kind of email marketer are you-

## Creating a product recommendation quiz

In a product recommendation quiz, a user will typically be asked a series of questions about their preferences, needs, and lifestyle. Based on their responses, the quiz will generate a list of recommended products that are tailored to their specific needs and interests.

Here is an example of a product recommendation quiz to suggest a coffee based on your preferences-

## Creating a calculator to collect essential information

You can collect essential information by asking simple questions and calculating an output based on the responses.

a. Here is an example of a BMI calculator. It is much easier to ask for the recipient’s weight and height and calculate the BMI rather than directly asking the recipient what is your BMI

b. Here is an example of a compound interest calculator where the recipient can enter the principal, time period and select an investment option based on their risk tolerance.

## Creating a scored quiz or a knowledge test for assessment

Scored quizzes are a type of quiz that assigns points or scores to each answer, allowing the person taking the quiz to receive a score or result that corresponds to their responses.

Here is an example of a scored quiz-

## What are variables?

- Variables are questions whose responses will be used to calculate the output of the formula.

In the above example, the following questions are variable questions-

a. What is the capital of France?

b. Which planet is closest to the Sun?

c. Which is the first Sherlock Holmes novel written by Sir Arthur Conan Doyle?

- The following input types can be used as variables in the formula-

a. Single line input

b. Dropdown

c. Radio

d. Checkbox

e. Single select chip

f. Multi select chip

Variable questions can span across multiple steps. For example, formula field in step 4 can use questions in step 1, 2 and 3 as variable questions.

## How to create a formula in Mailmodo?

** Step 1:** Add a form in the editor. Add questions which you want to use as variables in the formula.

** Step 2: **Once you have added variable questions, add the formula field.

** Step 3:** Give a suitable label to the formula field output and click on Formula to configure it.

** Step 4: **After clicking on Formula, formula builder will open. Create the formula expression using variable questions, constants and operators

** Step 5: **Once you have entered a valid formula, you will be taken to step 2 of the formula builder. Here, you need to assign numeric values to questions with predetermined answer options. The value of the variable will be the numeric value of the option selected by the user. For example, in the screenshot below, the numeric value of the variable question “Select an investment plan” can be 0.05, 0.10 or 0.15.

** Step 6: **After assigning numeric values, click on Save Changes. Attempt the formula in preview mode and send a test email to make sure everything is working properly.

## Formula field validation

After configuring the formula, when you click on Next we will check whether your formula is valid or not. If the formula is invalid, you will see an error message as shown below.

Some of the common errors because of which the formula will be deemed invalid are-

- Formula does not contain any variable question. For example 4*3 will be considered invalid.
- The formula starts with asterisk (*), division operator (/), exponent operator (^), or a decimal point (.). For example, the expression *5*variableQuestion would be invalid.
- The formula contains consecutive asterisks (*), division operators (/), exponent operators (^) or decimal points (.). For example, 5**variableQuestion would be invalid.
- Opening parentheses is directly followed by asterisk (*), division operator (/), or exponent operator (^). For example (*4*variableQuestion) would be invalid.
- Number of opening parentheses is not equal to the number of closing parentheses. For example 5*((variableQuestion) would be invalid.
- Formula ends with addition operator (+),subtraction operator (-), multiplication operator (*), division operator (/), exponent operator (^) or decimal point (.). For example, 5*variableQuestion+ would be invalid.

Please note that this is not an exhaustive list.

## Operators

- While calculating the formula result BODMAS (also known as PEMDAS) will be followed. So, precedence order will be-

a. Brackets/Parentheses

b. Order of exponent

c. Multiplication and division (from left to right)

d. Addition and subtraction (from left to right)

You can learn more about BODMAS/PEMDAS here.

- Multiplication operation will be considered by default if:

a. Two variables are not separated by an operator. eg. varQues1varQues2 = varQues1*varQues2

b. Variable and constant are not separated by an operator. eg. 5varQues = 5*varQues

c. Variable/constant and opening parentheses are not separated by an operator (left to right). eg. varQues( = varQues*(

d. Closing parentheses and variable/constant are not separated by an operator (left to right). eg. )varQues1 = ...)*varQues1

## Multi select fields and numeric values

In case of multi select options, the value of the variable will be the sum of numeric values of all options selected by the user. For example, checkbox field is a multi select question.

The following numeric values are assigned to each option-

If the user selects the first three answer options then the value of the variable will be (1) + (-1) + (1) = 1.

## Notes and further use cases

1. All variable questions are converted to required fields to ensure the result is always calculated. If you want to make the variable questions optional, you can do so by selecting the individual question and unchecking the required box.

2. You can use the formula result as a variable in another formula (in the same form).

3. You can use the formula result as a decision question as well as a show hide question in display logic. Use formula field with step logic to configure advanced logic.

4. You can create journey branching logic based on the formula result.

5. Formula result will be recorded in submissions. You can also export the formula result as a part of export submissions.

**TABLE OF CONTENTS**