> ## Documentation Index
> Fetch the complete documentation index at: https://zenskar.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How-to guides: Manage billable metrics

> This document shows how to find, create, preview, edit, rename, and delete billable metrics, and how to move a billable metric to the SQL builder.

## Find a billable metric

### Prerequisites

* You need a role with the **Can Read Billable Metric** permission.

### Steps

1. Go to **Usage** > **Billable Metrics**.

   The list shows the [billable metrics](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) of your [organization](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#organization).

2. Optional: To narrow the list, click **FILTER**. In **Filter by...**, select **Name** or **Created At**. Select a condition and a value, and click **APPLY FILTER**.

   The list shows only the billable metrics that match. To remove all filters, click **Clear All Filters**.

3. Optional: To sort the list, click a column header. Click it again to sort in descending order, and a third time to remove the sorting.

4. In **Search Billable Metric**, enter part of the name, and select the billable metric from the results. You can also click the billable metric in the list.

The billable metric opens in the editor.

See [Billable Metrics screen: controls, columns, and filters](https://zenskar.com/docs/20260301/zenskar-modules/usage/reference/billable-metrics.md#billable-metrics-screen-controls-columns-and-filters).

## Create a billable metric

### Prerequisites

* You need a role with the **Can Create Billable Metric** and **Can Read Billable Metric** permissions.
* The [usage-event collection](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#usage-event-collection) or the [data source](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#data-source) that the billable metric reads must exist. See [Create a usage-event collection](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/usage-events.md#create-a-usage-event-collection) and [Add a data source](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/data-sources.md#add-a-data-source).

### Steps

1. Go to **Usage** > **Billable Metrics**.

2. Click **ADD NEW BILLABLE METRIC**. The **Add New Billable Metric** screen opens with **VISUAL BUILDER** selected.

3. Choose the builder:

   | Builder | Choose it when |
   | - | - |
   | [Visual builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#visual-builder) | The [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) reads one usage-event collection or one table of [synced usage data](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#synced-usage-data) from a [synced data source](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#synced-data-source), and gives one number for each customer and period. |
   | [SQL builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#sql-builder) | The billable metric needs a [remote data source](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#remote-data-source), [dimensions](https://en.wikipedia.org/wiki/Dimension_\(data_warehouse\)), or logic that the visual builder does not cover. |

   You can start in the visual builder and move to the SQL builder later. You cannot move back. See [Move a billable metric to the SQL builder](#move-a-billable-metric-to-the-sql-builder).

4. Build the billable metric in the builder that you chose:

   > [tab] Visual builder
   >
   > 1. Under **Select tables & filters**, in **Table Name**, select the table. Usage-event collections are listed under **Usage Event** by their [API slug](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#api-slug). Tables of synced usage data are listed under **Data source**.
   >
   > 2. Optional: Click **+ ADD FILTER**. Select a **Column** and a **Condition**, and enter a **Value**. Repeat for each filter. To remove a filter, click its delete icon.
   >
   > 3. Optional: To add a group of filters, click **+ NEW FILTER GROUP**. To switch between AND and OR, click the AND or OR button between the filters or the groups. To remove every group except the first, click **CLEAR ALL FILTER GROUPS**.
   >
   > 4. Click **NEXT**.
   >
   > 5. Under **Map customer**, in **Your customer column**, select the column that identifies the customer. In **Zenskar customer column**, select **email**, **external\_id**, **customer name**, or **Custom attribute: `<name>`**.
   >
   >    A [custom attribute](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#custom-attribute) shows only when it belongs to customers and has the [custom attribute type](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#custom-attribute-type) Text, Whole number, or Dropdown.
   >
   > 6. Click **NEXT**.
   >
   > 7. Under **Set date field**, in **Column**, select the column that dates each row. If it is not `timestamp`, select its **Date Format**.
   >
   > 8. Click **NEXT**.
   >
   > 9. Under **Set Billable Metric over**, in **Select calculation type**, select the [calculation type](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#calculation-type). In **Select column to calculate over**, select the column.

   > [tab] SQL builder
   >
   > > [!CAUTION]
   > >
   > > After you click **EDIT** and confirm, the visual builder is locked in the editor. After you save, the billable metric cannot return to the visual builder. To keep the visual builder, leave the editor without saving.
   >
   > 1. Click **SQL BUILDER**. The editor shows a read-only query.
   >
   > 2. Click **EDIT**. In **SQL Builder Edit Access**, click **YES**.
   >
   > 3. Under **SOURCE OF DATA**, select **Synced Data**, or **Remote Data** and the data source in **Remote Datasource**.
   >
   >    **Synced Data** covers the usage-event collections and the synced usage data. One query uses one kind of source. When you switch a query that uses a remote data source to **Synced Data**, the **Source Of Data Compatibility** window opens. Click **PROCEED** to switch, or **CANCEL** to keep the remote data source.
   >
   > 4. In the editor, write the query.
   >
   >    A query on usage-event collections and synced usage data uses [ClickHouse SQL](https://clickhouse.com/docs/sql-reference). The query returns a column named `quantity`. Each other column that it returns is a dimension.
   >
   > 5. Optional: To find tables and columns, use **Data Navigator**. To copy the name of a table for the query, hover over the table, and click its copy icon.
   >
   > 6. Optional: To insert a [Zenskar SQL variable](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#zenskar-sql-variable), use **Zenskar Variables**.
   >
   >    Write a [contract](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#contract) or [product](https://zenskar.com/docs/20260301/zenskar-modules/products/glossary.md#product) variable as `{{contract.<field>}}` or `{{product.<field>}}`. **Zenskar Variables** also lists one variable for each custom attribute of the customer, the contract, and the product.

5. Optional: Check the result. See [Preview a billable metric](#preview-a-billable-metric).

6. Click **CREATE BILLABLE METRIC**. The **Choose Billable Metric Name** window opens.

   **CREATE BILLABLE METRIC** is available on the last step of the visual builder, or in the SQL builder after you click **EDIT** and confirm.

7. Enter the name.

8. Click **CREATE BILLABLE METRIC**.

Zenskar saves the billable metric. The **Billable Metrics** list opens.

See [Billable metric editor: builders, fields, and preview](https://zenskar.com/docs/20260301/zenskar-modules/usage/reference/billable-metrics.md#billable-metric-editor-builders-fields-and-preview).

## Preview a billable metric

Run a billable metric for a customer and a period before you save it.

### Prerequisites

* You need a role with the **Can Read Billable Metric** permission.

### Steps

1. Open the [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) in the editor, or build a new one. See [Create a billable metric](#create-a-billable-metric).
2. Under **Query preview**, in **Search By Customer Name, External ID**, select the customer. In the [visual builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#visual-builder), the field is available from **Map customer** on.
3. In the [SQL builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#sql-builder), if the query uses a [contract](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#contract) or [product](https://zenskar.com/docs/20260301/zenskar-modules/products/glossary.md#product) variable, select the contract in **Contract** or the product in **Product**.
4. In **Billing Period**, select the first and last days of the period. In the visual builder, the field is available from **Set date field** on.
5. Click **RUN QUERY**. In the SQL editor, you can also press Ctrl+Enter, or Cmd+Enter on a Mac.

   The preview runs only when each variable that the query uses has a value, and **Billing Period** has both dates.

The table under **Query preview** shows the result. When the query has an error, the table area shows the error. To download the result as a CSV file, click **Export Results**.

See [Query preview](https://zenskar.com/docs/20260301/zenskar-modules/usage/reference/billable-metrics.md#query-preview).

## Edit a billable metric

### Prerequisites

* You need a role with the **Can Update Billable Metric** and **Can Read Billable Metric** permissions.

### Steps

> [!WARNING]
>
> A change to a [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) applies to every [pricing preset](https://zenskar.com/docs/20260301/zenskar-modules/products/glossary.md#pricing-preset) that uses it. It can affect [contracts](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#contract) and invoices. Check which pricing presets use the billable metric before you save.

1. Go to **Usage** > **Billable Metrics**.

2. Click the billable metric. You can also open its actions menu and click **Edit**.

   The billable metric opens in the editor, with its name as the title.

3. Change the billable metric in the builder that it uses:
   * A billable metric from the [visual builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#visual-builder) opens at **Set Billable Metric over**. To change an earlier step, click **BACK**.
   * A billable metric from the [SQL builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#sql-builder) opens with the query ready to edit.

4. Optional: Check the result. See [Preview a billable metric](#preview-a-billable-metric).

5. Click **SAVE CHANGES**.

Zenskar saves the billable metric. The editor stays open.

See [Billable metric editor: builders, fields, and preview](https://zenskar.com/docs/20260301/zenskar-modules/usage/reference/billable-metrics.md#billable-metric-editor-builders-fields-and-preview).

## Move a billable metric to the SQL builder

Move a billable metric from the visual builder to the SQL builder, for example to add a dimension or a condition that the visual builder does not cover.

### Prerequisites

* You need a role with the **Can Update Billable Metric** and **Can Read Billable Metric** permissions.

### Steps

> [!CAUTION]
>
> After you save, the [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) cannot return to the [visual builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#visual-builder). Preview the converted query before you save.

1. Open the billable metric in the editor. See [Edit a billable metric](#edit-a-billable-metric).

2. Click **SQL BUILDER**.

   Zenskar converts the settings of the visual builder into a query. The editor shows the converted query, read-only.

3. Click **EDIT**. In **SQL Builder Edit Access**, click **YES**.

4. Optional: Change the query.

5. Preview the billable metric. See [Preview a billable metric](#preview-a-billable-metric).

6. Click **SAVE CHANGES**.

Zenskar saves the billable metric as a query. **VISUAL BUILDER** is no longer available for it. To keep the visual builder, leave the editor before you save.

See [SQL builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/reference/billable-metrics.md#sql-builder).

## Rename a billable metric

### Prerequisites

* You need a role with the **Can Update Billable Metric** and **Can Read Billable Metric** permissions.

### Steps

1. Open the [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric) in the editor. See [Edit a billable metric](#edit-a-billable-metric).
2. Next to the name in the title, click the pencil icon. The **Update Billable Metric Name** window opens.
3. Enter the new name.
4. Click **UPDATE**.

Zenskar saves the new name right away, without **SAVE CHANGES**. The calculation does not change.

## Delete a billable metric

### Prerequisites

* You need a role with the **Can Delete Billable Metric** and **Can Read Billable Metric** permissions.

### Steps

> [!CAUTION]
>
> You cannot restore a deleted [billable metric](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#billable-metric). Zenskar deletes it even when a [pricing preset](https://zenskar.com/docs/20260301/zenskar-modules/products/glossary.md#pricing-preset) uses it, which can affect [contracts](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#contract) and invoices. Check which pricing presets use it before you delete it.

1. Go to **Usage** > **Billable Metrics**.
2. Open the actions menu of the billable metric, and click **Delete**.
3. In **Delete Billable Metric**, click **DELETE**.

Zenskar deletes the billable metric. The billable metric disappears from the list.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.