> ## 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.

# Reference: Billable metrics

> This document presents the screens, fields, permissions, API operations, and troubleshooting of billable metrics.

## Billable Metrics screen: controls, columns, and filters

The **Billable Metrics** screen lists 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). To open it, go to **Usage** > **Billable Metrics**.

### Controls

| Control | Description |
| - | - |
| **Search Billable Metric** | Finds billable metrics whose name contains the text that you enter. Selecting a result opens the billable metric in the editor. |
| **ADD NEW BILLABLE METRIC** | Opens the **Add New Billable Metric** screen. |
| **FILTER** | Adds a filter to the list. See [Filters](#filters). |

### Columns

| Column | Content | Sortable |
| - | - | - |
| **Name** | The name of the billable metric. Click the row to open the billable metric in the editor. | Yes |
| **Created At** | The date when the billable metric was created. | Yes |

Click a sortable column header to sort in ascending order. Click it again to sort in descending order. Click it a third time to remove the sorting.

Each row has an actions menu with **Edit** and **Delete**. **Edit** opens the billable metric in the editor. **Delete** opens the **Delete Billable Metric** window. **DELETE** there deletes the billable metric.

### Filters

| Filter | Values | Conditions |
| - | - | - |
| **Name** | Text | Conditions for text, such as **contains** and **equals** |
| **Created At** | A date | Conditions for dates, such as **is before** |

After you set a filter, click **APPLY FILTER**. To remove all filters, click **Clear All Filters**.

## Billable metric editor: builders, fields, and preview

**ADD NEW BILLABLE METRIC** opens the editor as the **Add New Billable Metric** screen. Clicking a billable metric in the list opens the editor with the name of the billable metric as its title.

### Header

| Control | Description |
| - | - |
| Pencil icon | It shows next to the name of a saved billable metric. It opens the **Update Billable Metric Name** window. **UPDATE** there saves the new name right away. |
| **GO BACK** | Returns to the previous screen without saving. |
| **CREATE BILLABLE METRIC** | It shows for a new billable metric. It opens the **Choose Billable Metric Name** window. **CREATE BILLABLE METRIC** there saves the billable metric. |
| **SAVE CHANGES** | It shows for a saved billable metric. It saves the changes. The editor stays open. |
| **VISUAL BUILDER**, **SQL BUILDER** | Switch between the builders. Clicking **VISUAL BUILDER** while it is unavailable opens the **Visual Builder Disabled** window. |

| Property | Constraint |
| - | - |
| **CREATE BILLABLE METRIC** | It is available on the last step of the [visual builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#visual-builder), or in the [SQL builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#sql-builder) after **EDIT** is confirmed. |
| **VISUAL BUILDER** | After **EDIT** is confirmed in the SQL builder, **VISUAL BUILDER** is unavailable in the editor. |
| | After the billable metric is saved as a query, **VISUAL BUILDER** stays unavailable. |

### Visual builder

**BACK** and **NEXT** move between the four steps.

| Step | Field | Details |
| - | - | - |
| **Select tables & filters** | **Table Name** | The table. [Usage-event collections](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#usage-event-collection) 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](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#synced-usage-data) from [synced data sources](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#synced-data-source) are listed under **Data source**. |
| | **+ ADD FILTER** | Adds a filter with **Column**, **Condition**, and **Value**. The conditions depend on the data type of the column. The delete icon removes the filter. |
| | **+ NEW FILTER GROUP** | Adds a group of filters. The AND or OR button between filters or groups switches between AND and OR. **CLEAR ALL FILTER GROUPS** removes every group except the first. |
| **Map customer** | **Your customer column** | The column that identifies the customer. The default is `customer_id`. |
| | **Zenskar customer column** | **email**, **external\_id**, **customer name**, or **Custom attribute: `<name>`**. The default is **external\_id**. |
| **Set date field** | **Column** | The column that dates each row. The default is `timestamp`. |
| | **Date Format** | The format of the dates in the column. It shows when **Column** is not `timestamp`. |
| **Set Billable Metric over** | **Select calculation type** | **COUNT**, **SUM**, **MAX**, **AVG**, **MIN**, or **UNIQUE COUNT**. The default is **COUNT**. See [Calculation types: how the visual builder aggregates](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/billable-metrics.md#calculation-types-how-the-visual-builder-aggregates). |
| | **Select column to calculate over** | The column that the calculation type applies to. |

| Property | Constraint |
| - | - |
| **NEXT** | **NEXT** does not move on when the table has no columns. |
| | **NEXT** does not move on when a filter is incomplete. |
| **Table Name** | The visual builder does not read [remote data sources](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#remote-data-source). |
| **Zenskar customer column** | A [custom attribute](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#custom-attribute) shows only when it belongs to customers. |
| | A custom attribute shows only when its [custom attribute type](https://zenskar.com/docs/20260301/zenskar-modules/settings/glossary.md#custom-attribute-type) is Text, Whole number, or Dropdown. |

### SQL builder

| Control | Description |
| - | - |
| Editor | The query. A query on usage-event collections and synced usage data uses [ClickHouse SQL](https://clickhouse.com/docs/sql-reference). The format and copy icons format and copy the query. |
| **SOURCE OF DATA** | **Synced Data** or **Remote Data**. **Synced Data** covers the usage-event collections and the synced usage data. With **Remote Data**, **Remote Datasource** selects the [data source](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#data-source). When a query that uses a remote data source switches to **Synced Data**, the **Source Of Data Compatibility** window opens, with **PROCEED** and **CANCEL**. |
| **Data Navigator** | Lists the tables and columns. The copy icon next to a table copies its name for the query. |
| **Zenskar Variables** | Lists the [Zenskar SQL variables](https://zenskar.com/docs/20260301/zenskar-modules/usage/glossary.md#zenskar-sql-variable) of the customer and the period. It also lists one variable for each custom attribute of the customer, the [contract](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#contract), and the [product](https://zenskar.com/docs/20260301/zenskar-modules/products/glossary.md#product). See [Zenskar SQL variables: values that Zenskar fills in](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/billable-metrics.md#zenskar-sql-variables-values-that-zenskar-fills-in). |

| Property | Constraint |
| - | - |
| Editor | The query is read-only until you click **EDIT** and confirm with **YES** in **SQL Builder Edit Access**. |
| | After you save, the billable metric cannot return to the visual builder. |
| Query | The query returns a column named `quantity`. Each other column that it returns is a dimension. |
| | Zenskar rejects a query whose Zenskar SQL variables are not valid. |
| **SOURCE OF DATA** | A query uses one kind of source. |

### Query preview

| Control | Description |
| - | - |
| **Search By Customer Name, External ID** | The customer of the preview. In the visual builder, it is available from **Map customer** on. |
| **Contract**, **Product** | They show in the SQL builder when the query uses a contract or product variable. |
| **Billing Period** | The first and last days of the period. In the visual builder, it is available from **Set date field** on. |
| **RUN QUERY** | Runs the preview. In the SQL editor, Ctrl+Enter or Cmd+Enter also runs it. |
| **Export Results** | Downloads the result as a CSV file. |

| Property | Constraint |
| - | - |
| **RUN QUERY** | In the SQL builder, the preview runs only when each variable that the query uses has a value. |
| | In the visual builder, the preview runs only when **Billing Period** has both dates. |

## Permissions

| Action | Required permission |
| - | - |
| View billable metrics and open the editor | **Can Read Billable Metric**, in the **BILLABLE\_METRIC** group |
| Preview a billable metric | **Can Read Billable Metric** |
| Create a billable metric | **Can Read Billable Metric** and **Can Create Billable Metric** |
| Edit a billable metric, move it to the SQL builder, or rename it | **Can Read Billable Metric** and **Can Update Billable Metric** |
| Delete a billable metric | **Can Read Billable Metric** and **Can Delete Billable Metric** |

The default **Owner** role has every permission. The default **User** role has read permissions only.

## API reference

| Operation | API reference |
| - | - |
| List billable metrics | [List billable metrics](https://zenskar.com/docs/api-reference/billable-metrics/list-billable-metrics.md) |
| Get a billable metric | [Get billable metric](https://zenskar.com/docs/api-reference/billable-metrics/get-billable-metric.md) |
| Create a billable metric | [Create billable metric](https://zenskar.com/docs/api-reference/billable-metrics/create-billable-metric.md) |
| Update a billable metric | [Update aggregate](https://zenskar.com/docs/api-reference/billable-metrics/update-aggregate.md) |
| Delete a billable metric | [Delete aggregate](https://zenskar.com/docs/api-reference/billable-metrics/delete-aggregate.md) |

The API reference names some of these operations "aggregate". An aggregate is a billable metric.

## Troubleshooting

| Problem | Cause | Solution |
| - | - | - |
| **CREATE BILLABLE METRIC** is unavailable. | The visual builder is not on **Set Billable Metric over**, or the SQL builder is still read-only. | Finish the four steps, or click **EDIT** and confirm. |
| **NEXT** does not move on. | The table has no columns, or a filter is incomplete. | Choose another table, or complete the filter. |
| The tables of a remote data source cannot be used in the visual builder. | The visual builder does not read remote data sources. | Build the billable metric in the SQL builder. |
| Zenskar rejects a query. | The Zenskar SQL variables of the query are not valid. | Correct the variables, as [Zenskar SQL variables: values that Zenskar fills in](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/billable-metrics.md#zenskar-sql-variables-values-that-zenskar-fills-in) describes them. |
| The preview does not run in the SQL builder. | The query uses a variable that has no value. | Select the customer, the contract, the product, or the dates that the query uses. |
| The preview does not run in the visual builder. | **Billing Period** lacks a date. | Select both dates of **Billing Period**. |
| The preview shows an error. | The query has an error. | Correct the query, and run the preview again. |
| A billable metric does not give a number for each combination of [dimension values](https://zenskar.com/docs/20260301/zenskar-modules/products/glossary.md#dimension-value). | The visual builder cannot group rows by dimensions. | [Move the billable metric to the SQL builder](https://zenskar.com/docs/20260301/zenskar-modules/usage/how-to-guides/billable-metrics.md#move-a-billable-metric-to-the-sql-builder), and return the dimensions as columns. |
| **VISUAL BUILDER** is unavailable for a billable metric. | **EDIT** was confirmed in the SQL builder, or the billable metric was saved as a query. | Leave the editor without saving, or create a new billable metric in the visual builder. |
| A [billing period](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#billing-period) has no [quantity](https://zenskar.com/docs/20260301/zenskar-modules/contracts/glossary.md#quantity) from a billable metric. | No rows matched. The query does not replace an empty result with 0. | To get 0 instead, replace an empty result with 0 in the query, such as with `COALESCE`, as [Results for each customer and period](https://zenskar.com/docs/20260301/zenskar-modules/usage/concepts/billable-metrics.md#results-for-each-customer-and-period) describes. |


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