# Metrics

> Metrics are used to define a calculation once and reuse it in the entire app. For example, you can make a metric to calculate the number of invoices, or a metric to calculate the average amount. You can further reuse these metrics in different charts.

## Introduction

Metrics are used to define a calculation once and reuse it in the entire app. For example, you can make a metric to calculate the number of invoices, or a metric to calculate the average amount. You can further reuse these metrics in different charts.

:::note
You cannot preview or publish the app when adding or editing metrics.
:::

## Editing metrics

Follow these steps to edit a metric.

1. In the **Data Manager** panel, locate the metric you want to edit and select the Edit icon.![Edit icon](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-rename-section-icon-289309-c8e41793-c6525877.webp)

The **Edit KPI** window is displayed.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-docs-image-298698-9f6cfcb5-097bb149.webp)
2. Edit the the display name for the metric in the **Metric name** field and/or configure the rules for the metric.
3. Select **Save**.

## Adding metrics

If the metric you want to use is not available by default, you can create new metrics that can be used in your dashboards.

Follow these steps to add a new metric.

1. In the **Data Manager** panel, select **+New metric**. The **Create KPI** dialog is displayed.
2. Enter a descriptive name for the new metric in the **Metric name** field.
   :::tip
   It is a good practice to refer to the type of function you use to calculate the metric.
   :::
3. Configure the rules that define the metric.
   :::tip
   A preview of the metric calculation is displayed in the Create KPI panel.
   :::
4. Select **Save**.

The metric is added to the list of metrics in the **Data Manager**.

## Rules

### Elements of a rule

Below is a description of the elements a rule.

| Element | Description |
| --- | --- |
| Aggregation type | The type of the function that is used to calculate the metric. For example, `SUM` is used to calculate a *Total* value, `AVERAGE` is used to calculate an *Average* value. |
| Field used for aggregation | The field that is used to calculate the metric. |

#### Aggregation type

Below is an overview of the aggregation types available for configuring a rule.

| **Aggregation type** | **Returns** | **Field types allowed** |
| --- | --- | --- |
| `Input value` | a constant | number, currency, percentage |
| `Distinct count` | the number of unique values for the selected field | all |
| `Count` | the number of values for the selected field | all |
| `Case average` | the sum of all values for selected field divided by the number of cases | number, duration , currency |
| `Average` | the sum of all values for selected field divided by the number of records in the table of the selected field | number, duration |
| `Min` | the smallest value for the selected field | number, duration , currency |
| `Max` | the largest value for the selected field | number, duration , currency |
| `Percentage` | the percentage of TRUE values for the selected field | boolean |
| `Sum` | the sum of all values for the selected field | number, duration , currency |

#### Using static values

In stead of an aggregation type, you can select to use a constant value to calculate the metric. If you select the **Input value** option from the list of aggregations, you can enter a value and select the field type.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-docs-image-370933-7e81c15e-45395a9a.webp)

### Configuring rules

Follow these steps to configure a rule.

1. Select the function that you want to use to calculate the metric from the Aggregation types list.
   :::tip
   You can start typing the aggregation type and select Enter. ![docs image](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-docs-image-307469-a54f76b0-d5674176.webp)
   :::
2. Select the field that you want to use to calculate the metric from the **Field used for aggregation** drop-down list.
   :::note
   The **Field used for aggregation** drop-down list only contains fields that are applicable for the selected aggregation type.
   :::
3. If desired, apply filters to the values that should be considered for the evaluation of the aggregation used for the metric.
4. Select **Save** in the **Create KPI** panel.

Repeat these steps if you want to add another aggregation for the rule.

:::note
You can add up to two aggregations to define the rule. If you define two aggregations for the rule these will be evaluated as a division. In this case, you can select to display the results as a percentage value.
:::

#### Using multiple aggregations in a rule

You can add up to two aggregations to define the rule. If you define two aggregations for the rule, you can select the operator to be used to evaluate the rule. Below is an overview of the available operators.

| **Operator** | **Description** |
| --- | --- |
| + | addition |
| - | subtraction |
| x | multiplication |
| / | division* |

*) In case of a division, you can select to display the results as a percentage value.

The result type of the rule depends on the type of the input aggregations. Below is an overview of the supported input formats for the operators.

| **Operator** | **Rule** | **Result type** |
| --- | --- | --- |
| Addition | `numeric + numeric` | `numeric` |
|  | `duration + duration` | `duration` |
|  | `currency + currency` | `currency` |
|  | `percentage + percentage` | `percentage` |
|  | `timestamp + duration` | `timestamp` |
| Subtraction | `numeric - numeric` | `numeric` |
|  | `duration - duration` | `duration` |
|  | `currency - currency` | `currency` |
|  | `percentage - percentage` | `percentage` |
|  | `timestamp - duration` | `timestamp` |
|  | `timestamp - timestamp` | `duration` |
| Multiplication | `numeric x numeric` | `numeric` |
|  | `duration x numeric` | `duration` |
|  | `currency x numeric` | `currency` |
|  | `percentage x numeric` | `percentage` |
|  | `percentage x percentage` | `percentage` |
|  | `numeric x percentage` | `numeric` |
|  | `duration x percentage` | `duration` |
|  | `currency x percentage` | `currency` |
| Division | `numeric / numeric` | `numeric` |
|  | `duration / duration` | `numeric` |
|  | `currency / currency` | `numeric` |
|  | `percentage / numeric` | `percentage` |
|  | `duration / numeric` | `duration` |
|  | `currency / numeric` | `currency` |
| Percentage | `numeric / numeric` | `percentage` |
|  | `duration / duration` | `percentage` |
|  | `currency / currency` | `percentage` |

#### Null handling

`X / 0` will return `null`

`null / X` will return `null`

`X / null` will return `null`

#### Applying filters to an aggregation

Follow these steps to apply filters to an aggregation.

1. Select the aggregation for which to you want to apply filters.
2. Select **Add filter** in the **Create KPI** panel.
3. Define the filters as desired**.**

The ![](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-image-307500-6d2b82f5-5a3c7cb5.webp) icon is displayed next to the aggregation indicating that filters are applied for the aggregation.

:::tip
You can select the icon to see a preview of the applied filters.
:::

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-docs-image-307506-60bb5348-fd8406e1.webp)

#### Removing an aggregation

Follow this step to remove an aggregation from a rule.

1. Locate the aggregation you want to remove and select the ![](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-delete-icon-129868-220c2e6a-104ae3d1.webp) icon.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-docs-image-307485-282b5033-651f77c4.webp)

:::note
The aggregation is removed without any notification.
:::

## Deleting metrics

To keep your process app clean, you can delete metrics that are not used anymore. Follow these steps to delete a metric.

1. In the **Data Manager** panel, locate the metric you want to delete.
2. Hover over the metric name and select the ![Delete metric icon](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-delete-icon-129868-220c2e6a-104ae3d1.webp) **Delete metric** icon. A confirmation message is displayed.
3. Select **Delete**. See the illustration below.

   ![Confirmation message](https://dev-assets.cms.uipath.com/assets/images/process-mining/process-mining-delete-metric-confirmation-message-15505-b8ae1494-fe36e9b5.webp)

   :::note
   You can only delete user-created metrics. Metrics that are used in charts can not be deleted.
   :::
