# Formulas & multi-metrics

### Why use formulas?

*Formulas* can be used to convert values (seconds to milliseconds) or combine multiple filtered metrics into one. This enables you to view desired data without the need to looking at several charts and manually perform calculations.&#x20;

Formulas enable you to add one or more metrics to a mathematical expression to create an entirely new metric. Metrics created through a formula are called calculated metrics. You can reference existing metrics, numbers (`1`, `-2`, `4.513`) or mathematical constants such as π (`pi`). Parentheses `()` can be used to denote the order of operations within your expression.

***

### **Supported charts**

{% hint style="info" %}
Be sure to add one or more datasets before applying a formula to your chart.
{% endhint %}

The following lists all chart types where formulas may be used:

* *Bar chart*: Displays formula output as a new bar
* *Line chart*: Displays formula output as a new line
* *Table*: Displays formula output as a new column

***

### **Basic arithmetic functions**

The following lists the basic arithmetic functions supported; `x`, `y` represent constants or metric references:

<table><thead><tr><th width="263.33333333333326">Operation</th><th width="154">Usage</th><th>Examples</th></tr></thead><tbody><tr><td>Addition</td><td><code>+</code></td><td>1+1<br>{SampleMetric}+1</td></tr><tr><td>Subtraction</td><td><code>-</code></td><td>10-8<br>{SampleMetric}-20</td></tr><tr><td>Multiplication</td><td><code>*</code></td><td>2*3<br>5*{SampleMetric}</td></tr><tr><td>Division</td><td><code>/</code></td><td>1/2<br>1/{SampleMetric}</td></tr><tr><td>Unary subtraction</td><td><code>-x</code></td><td>-1<br>-{SampleMetric}</td></tr></tbody></table>

***

### **Math functions**

The following lists the mathematical functions that are supported:

| Operation         | Usage        | Examples                                       |
| ----------------- | ------------ | ---------------------------------------------- |
| Absolute value    | `abs(x)`     | <p>abs(-1)<br>abs({SampleMetric})</p>          |
| Square root value | `sqrt(x)`    | <p>sqrt(4)<br>sqrt({SampleMetric})</p>         |
| Ceiling function  | `ceil(x)`    | <p>ceil(1.67)<br>ceil({SampleMetric})</p>      |
| Floor function    | `floor(x)`   | <p>floor(3.2)<br>floor({SampleMetric})</p>     |
| Power function    | `power(x,y)` | <p>power(2,2)<br>power({SampleMetric}, 10)</p> |

***

### Using formulas

To add a formula to a *Bar chart*, *Line chart*, or *Table*:

* Select an existing *Analytics* dashboard and click *Edit dashboard,* or choose *+ Add dashboard* to create a new dashboard
* Select *+ Add panel* > Hover over panel > Click the edit icon
* Select *+ Add dataset* or *+ Add data column*; Repeat as needed
* Choose *+ Add formula* or *+ Add formula column* > Enter a name
* *Formula*: Enter the mathematical function. To reference an existing metric, type an open curly bracket { that displays a list of available metrics to reference
* *Formula* *unit*: Choose how the calculated metric is displayed. For example, if your formula outputs a percentage, you can select the *Percentage* option from the dropdown to display a percent % character next to your numerical output
* Click *Save*

{% hint style="info" %}
Referencing a calculated metric into another formula input is unavailable.
{% endhint %}

***

### Apply multi-metrics

*Analytics* can support multiple datasets within the same panel, allowing you to compare different metrics against each other in the same chart without the need to create individual charts for each metric. For example, you may want to compare the performance of different intents against each other over the same period of time.

{% hint style="info" %}
Multi-metrics are currently only supported for [*Bar charts, Line charts, and Tables*](https://docs.nlx.ai/platform/nlx-platform-guide/monitoring/creating-dashboards#chart-type).
{% endhint %}

As an example, let's compare the number of *Actions* invoked versus the number of *Data requests* invoked in a single *Line chart*:

* Select an existing *Analytics* dashboard and click *Edit dashboard,* or choose *+ Add dashboard* to create a new dashboard
* Select *+ Add panel* > Hover over panel > Click the edit icon
* Enter a name and description of the panel
* Select *Line chart* for *Chart* type
* Click *+ Add dataset* link > Enter name (in this example, we'll name it *Actions*)
  * Select the metric for the data to be measured, which in this case is *Actions invoked*
  * Select the time interval of how the data will be displayed in the line chart. *Day* will show the results on a daily basis
  * Select the *sum* aggregation to get the total counts of actions invoked
  * Select respective filters to create any subset of data
* Click *+ Add dataset* > Enter name (in this example, we'll name it *Data requests*)
  * Repeat steps above as done for the *Actions* dataset, except select the metric *Data requests invoked*
* Click *Save*

<div align="left" data-full-width="false"><figure><img src="https://2737319166-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHCxYxhIU0Bqkjj942mGk%2Fuploads%2FFCKA00KwQSJZmB11AvKc%2Fimage.png?alt=media&#x26;token=cb24eedf-c9ab-4c9d-9b07-c715ca457bc4" alt=""><figcaption><p><em>Actions</em> and <em>Data Requests</em> <em>Line chart</em> with legend</p></figcaption></figure></div>


---

# 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://docs.nlx.ai/platform/nlx-platform-guide/monitoring/analytics/formulas-and-multi-metrics.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.
