# calculate-column

## Description

<mark style="color:purple;">`calculate-column`</mark> *adaptor applies one of the following mathematical operations using values in two columns in a datatable*:

* `add`: Adds values in left column to values in right column (left + right).
* `subtract`: Subtract values in right column from values in left column (left - right).
* `multiply`: Multiplies values in left column by values in right column (left \* right).
* `divide`: Divides values in left column by values in right column (left / right).
* `percent`: Calculates the percentage ratio of values in left column out of values in right column (left / right \* 100).
* `exponent`: Calculates values in left column (raised) to the (power of) of values in right column (left \*\* right).

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable containing the column to be formatted.

**`left column`**\
Type: `text`\
Required: Yes\
The name of the column containing the values on the left-hand side of the operator.

**`right column`**\
Type: `text`\
Required: Yes\
The name of the column containing the values on the right-hand side of the operator.

**`operation`**\
Type: `text`\
Required: No\
The calculate operation to be used. Can be either `add`, `subtract`, `multiply`, `divide`, `percent`, or `exponent`. If unspecified, defaults to `add`.

**`result column`**\
Type: `text`\
Required: No\
The name of the column to which the calculated values will be added.

**`result unit`**\
Type: `text`\
Required: No\
An optional unit to be appended to the result. If unspecified, defaults to blank.

## Outputs

**`data`**\
Type: `datatable`\
A datatable with formatted values.

## Examples

### Example 1: Default behaviour.

#### Inputs:

`data`:

<table><thead><tr><th width="134.5">Location</th><th width="186">January case count</th><th width="195">February case count</th></tr></thead><tbody><tr><td>County X</td><td>27</td><td>15</td></tr><tr><td>County Y</td><td>58</td><td>80</td></tr></tbody></table>

`left column`: January case count

`right column`: February case count

#### Outputs:

* `data`:

<table><thead><tr><th width="134.5">Location</th><th width="186">January case count</th><th width="195">February case count</th><th>result</th></tr></thead><tbody><tr><td>County X</td><td>27</td><td>15</td><td>42</td></tr><tr><td>County Y</td><td>58</td><td>80</td><td>138</td></tr></tbody></table>

-> Added the values in `January case count` column to the values in `February case count` column. Results were displayed in a new column.

### Example 2: Calculate percentage column.

#### Inputs:

`data`:

<table><thead><tr><th width="134.5">Month</th><th width="126">Sales</th><th width="127">Total</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td><td>14580</td></tr><tr><td>Feb</td><td>5832</td><td>14580</td></tr></tbody></table>

`left column`: Sales

`right column`: Total

`result column`: Percentage

`result unit`: %

#### Outputs:

* `data`:

  <table><thead><tr><th width="149">Month</th><th>Sales</th><th>Total</th><th>Percentage</th></tr></thead><tbody><tr><td>Jan</td><td>1458</td><td>14580</td><td>10%</td></tr><tr><td>Feb</td><td>5832</td><td>14580</td><td>40%</td></tr></tbody></table>

-> Calculated the percentage ratio of values in `Sales` column out of values in `Total` column. The result was added to the `Percentage` column.


---

# 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://cgps.gitbook.io/data-flo/reference-guide/calculate-column.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.
