**Introduction**

Builders can create **calculations** and use them across the platform in the same way as **response variables**. Calculations can be inserted into **documents****,** **notifications**, **messages** or used to build out rules.

Check out the walkthrough video above to see them in action.

In this article, you'll learn how to:

- Access the Variables library
- Create a variable
- Insert a variable into a message, document or notification
- Troubleshoot invalid calculations
- Edit a variable
- Use the variables overview

### Variables library

The Variables library contains an overview of all of your bot's response and calculation variables. It's also where you can add or edit calculations.

Within the Flowchart, List view, or Notifications tabs, the library can be accessed via the tag on the far right of the window.

In the document editor, click Insert variable to see a list of your bot's variables & calculations.

### Create a variable

First, head to either List View or Flowchart. Then click on the Variables library tag located on the right of the Dashboard.

When you first open up the Variables library, you'll see:

- A drop-down field containing a list of existing calculations
- An overview of all of your existing response and calculation variables
- A purple 'Create new variable' button

To build out your first calculation, follow these steps:

**1. Click the Create new variable button**

A sidebar will appear where you can define the contents of your variable.

**2. Give the variable a name in the Variable name field**

This is for your reference only, similar to a message name.

**3. Set your Calculation result type**

Choose from the following result types:

**Number**- A numerical value

**Date**- A formatted date

**Percentage**- A percentage value

**Currency**- A numerical value formatted according to the international currency selected in Dashboard > My account > Currency.

**Duration**- A period of time defined by a number of days, weeks, months or years. The output will be presented as the smallest time unit available e.g. 14 days will be presented as 2 weeks when inserted in documents, notifications or messages.

**4. Create your calculation in the Calculation field**

Start writing the calculation and ensure it matches the result type selected in Step 3. The mathematical order of operations follows the BODMAS rules.

To create a calculation:

- Click into the Calculation field and insert your response by using the @ key to open a list of available variables.
- Select a variable from the dropdown. You may also use the insert variable button (x) in the toolbar below.
- Use standard mathematical operators to add to your calculation. These include: +, -, /, *.
- To validate the operator, hit space or enter/return on your keyboard.
- After adding your operator, type in numerical values or insert further variables to complete your calculation.

For calculating dates, you can also type a number (e.g. 12) and then click on the token to select the duration timeframe.

You can also type in the number of days, weeks, months, and years (e.g. “1day” or “2weeks”, or “3months”) and confirm with your space/enter key.

Please note:

- There should be no space between the number and the time unit. Date calculations include the first day and exclude the last day (e.g. 1 June - 5 June = 4 days)
- 1 week = 7 days
- 1 month = 30 days
- 1 year = 365 days

Once you’ve built out your calculation, click on the Create button to finalise the variable.

Your variable can now be accessed in the Variables library workspace.

### Invalid calculations

You may see some of the following messages when adding your calculations. Here's what they mean:

`It looks like your formula contains invalid characters `

- The calculation field contains invalid characters (e.g. duration + #)

`It looks like your formula is missing brackets`

- Bracket pairs are incomplete (i.e. missing an open or closed bracket)

`It looks like your formula is missing an operator, or is incomplete `

- The calculation is incomplete (e.g. ends with an operator)
- The calculation has two operators after another (e.g. value + - value)
- The calculation contains values/variables without an operator

`Formula is required`

- The field is empty

`It looks like your formula contains a type combination that isn't allowed `

- The variable/value combination is invalid (e.g. date + currency)
- The variable/value and operator combination is invalid (e.g. date * date)
- The variable/value is not allowed (e.g. decimals in durations, such as 1.7 months)

`Oh no, your formula isn't matching the result type.`

- The calculation isn't matching the result type selected

### Insert a variable

Variables can be inserted into bot messages, notifications, and/or generated documents via the Insert variable button. Here's where to find it:

**Messages**

In the toolbar in the bottom right of the Message text field

**Notifications**

In the toolbar in the bottom right of the Content field

**Documents (in both the Word & Web editors)**In the top toolbar

### Edit a variable

To edit your variable, simply follow these steps:

- Click on the Variables library tag
- Either:
- Select the variable you'd like to edit from the drop-down, or
- Click on the variable pill in the Overview to open the variable to edit

### Delete a variable

Click the red Delete button within the Variables library sidebar and follow the prompts.

### Variables overview

Each variable has an overview that tells the builder where in their bot a variable is used. You can find the variables overview in the Variables library.