# Calculation

Define complex calculations you can use for final prices or rates based on the inputs in the rest of your model.

<figure><img src="https://1110149073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu89vYHjuY9Vj4vhZX5IZ%2Fuploads%2Fh00ibOQYJqxdyS57pNA8%2FScreenshot%202024-04-29%20at%2017.37.49.png?alt=media&#x26;token=7de078e7-44d1-4ec5-8b25-be7b79148790" alt="" width="375"><figcaption><p>The Calculation step</p></figcaption></figure>

{% hint style="info" %}
**How might you use the 'Calculation' step?**

If you've creating a pricing model for insurance, you'll need to calculate premiums as well as a variety of rates and commissions.
{% endhint %}

## 1. Write your calculation

Once you've added the 'Calculation' step and named it, like you will with any other step in the Build tool ([more on that here](https://swallow-1.gitbook.io/swallow/build/step-builder)), you'll need to write your calculation.

To get started, click the cog symbol in the top right of the 'Calculation' step.

There are three fields to complete for this step.

### Output Key

This will be the key that you will use in all subsequent expressions and calculations, including in the final 'Output' step of your model, so it will need to be unique, descriptive, and easy to understand.&#x20;

You can use letters, symbols and numbers, but no spaces.

### Formula

This is the formula for your final calculation.&#x20;

Here's an example of how you would structure an formula multiplying your base price against your vehicle peril risk factor and driver peril risk factor, rounding the result:

`round({{driver_peril}} * {{vehicle_peril}} * {{base}}, 4)`

To learn how to structure your expression in more detail and to see the full list, check out our full page on [syntax](https://swallow-1.gitbook.io/swallow/your-first-model/essential-concepts/syntax "mention"). Here you can learn how to structure your expression in more detail, debug and see a full glossary.

### Default Value

This is the default value you want to set for the calculation.

This is the data the model will default to should any values not return as expected.

## 2. Save the step

Once you're happy with your calculation, just press the 'Save' button in the top right of the screen. You're now ready to head back to the 'Build' screen.

<figure><img src="https://1110149073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu89vYHjuY9Vj4vhZX5IZ%2Fuploads%2FSsAAZhH3dnz67i3jRdKZ%2FScreenshot%202024-05-11%20at%2016.21.13.png?alt=media&#x26;token=30849d88-4e70-4b00-9380-77b35601f69e" alt="" width="111"><figcaption><p>Save step button</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://swallow-1.gitbook.io/swallow/build/making-calculations/calculation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
