> ## Documentation Index
> Fetch the complete documentation index at: https://lightdash-mintlify-ca973f84.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Using custom fields

> The fields that you see in your `dimensions` and `metrics` are created by the people maintaining your Lightdash project. But, you can create new custom dimensions or metrics for quick calculations and binning on the fly. On this page, we'll explain what custom dimensions and metrics are and how to use them.

## Custom metrics

Custom metrics are only saved in the chart they're used in and will not be saved in the list of `metrics` available if you open the same Table to build a new chart. Metrics written to your dbt project (or YAML metrics) are reusable by everyone in your project and will always show up in the side bar of available metrics for a Table. We recommend [writing back custom metrics](/guides/developer/dbt-write-back#write-back-metrics-from-custom-metrics) that you're using/creating frequently so they become reusable, governed and available for everyone else to build from.

To create a custom metric:

1. Click on the dimension's three-dot `options` menu
2. Click on one of the options available (e.g. `Count Distinct`)
3. Confirm your changes

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-metric-creating.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=73048f454a7e7ebb640bf1c42a31aa84" width="399" height="440" data-path="images/guides/custom-fields/custom-metric-creating.png" />
</Frame>

Then, your new metric will be added to your results table automatically and will appear in the `custom metrics` space in your sidebar.

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-metric-added.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=42bf1db1914b74f6dfab4139f773643b" width="1571" height="864" data-path="images/guides/custom-fields/custom-metric-added.png" />
</Frame>

If you want to delete the custom metric, you can just click on the three-dot `options` menu and hit `Remove custom metric`

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-metric-deleting.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=b44bad624d55a738db484a8d107ebd92" width="412" height="254" data-path="images/guides/custom-fields/custom-metric-deleting.png" />
</Frame>

### Custom metric types

To learn more about the custom metric types, read the [metrics reference documentation here](/references/metrics). Only aggregate metric types are available as custom metrics.

### Adding filters to your custom metric

You can add filters to limit the rows included in your metric aggregation. You can add filters when:

1. You create a custom metric:

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-metric-add-filter-while-creating.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=634997ba32d6395b39d3fa8602bebf91" width="899" height="604" data-path="images/guides/custom-fields/custom-metric-add-filter-while-creating.png" />
</Frame>

2. You edit an existing custom metric:

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-metric-add-filter-while-edting.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=ec1a6051489ffa3aa506ea7bdbcf5e6f" width="884" height="610" data-path="images/guides/custom-fields/custom-metric-add-filter-while-edting.png" />
</Frame>

## Custom dimensions

Dimensions are used to group results in your query, or filter values from your results.

Sometimes, a group or filter that you need hasn't been added to your project, so you can use a custom dimension to create a grouping or filter on-the-fly.

These dimensions are not saved to the table permanently. They are only available in the saved chart or query that they were created in.

### Using custom dimensions in table calculations

You can reference custom dimensions in your table calculations without needing to qualify them with a table name. Simply use the custom dimension name directly in your calculation formula, just as you would with any other dimension.

### Bin

Bins are used to split out values of a numeric dimension into custom sets of ranges. Bins can only be used with dimensions that are numeric. Fixed bins (fixed number and fixed width) will update automatically if the min or max values of your dimension change.

To create a bin custom dimension, you just need to:

1. Click on a dimension's three-dot `options` menu
2. Click on the `bin` option
3. Setup + create your dimension

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-dimension-creating.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=e0ee03b4baef6ffbc87e5bfe2c160208" width="397" height="518" data-path="images/guides/custom-fields/custom-dimension-creating.png" />
</Frame>

Then, your new dimension will be added to your results table automatically and will appear in the `custom dimensions` space in your sidebar.

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-dimension-bins.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=fc5e6d3053e5337da67c4c51330cf995" width="1158" height="797" data-path="images/guides/custom-fields/custom-dimension-bins.png" />
</Frame>

There are three ways that you can set up your bins:

**1. Fixed number of bins**

You pick the number of bins that you want to group your dimension into and Lightdash automatically defines the ranges for your bins. The ranges that Lightdash generates for the bins are equal to the range of the values in your dimension divided by the number of bins you selected.

**2. Fixed width**

You pick the width (a.k.a. ranges) for your bins and Lightdash automatically defines a set of bins with those widths. The number of bins that Lightdash generates is equal to the range of values in your dimension divided by the fixed width that you picked for your bins.

**3. Custom range**

You manually define the min and max values for each bin. The custom range option is the only binning option that will not automatically update if the min or max values of your dimension change (you would need to manually adjust your custom bins or some values could not be included in your bins).

### Custom SQL

Custom SQL dimensions let you pull in new data directly from your database, which means they can sometimes be used to bypass access restrictions. **Only users with admin or developer permissions can create custom SQL dimensions**. Regular users will not see this option.

<Info>
  **Security note:**\
  Custom SQL dimensions can query any data from your warehouse, so they should only be created by trusted users (admins and developers). For most cases, it's safer and more reusable to define dimensions in your dbt files. If you want to make a custom SQL dimension reusable, use the [dbt write-back](https://docs.lightdash.com/references/dbt-write-back#dbt-write-back) feature to move it into your dbt project.
</Info>

#### When to use custom SQL dimensions

* **Quickly create new groupings or calculations** that aren't yet available in your project.
* **Reference other dimensions** from the main table and joined tables in your explore.
* **Prototype new logic** before moving it to your dbt project.

#### When *not* to use custom SQL dimensions

* If you need the dimension to be **reusable** or **governed** for your whole team.
* If you want to ensure **consistent access control** and security.

#### Example: Categorizing order totals

In this example, let's explore the `orders` table and create a custom dimension that categorizes my orders' totals into three categories: `low`, `medium`, and `high`.

You can click on the button to add a custom dimension on the sidebar:

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-dimension-sql-add.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=b28cb69097965cbc8b775d895c5782a3" width="396" height="280" data-path="images/guides/custom-fields/custom-dimension-sql-add.png" />
</Frame>

Then you can write your SQL query to create your custom dimension:

```sql theme={null}
CASE
  WHEN ${orders.subtotal} < 100 THEN 'low'
  WHEN ${orders.subtotal}  < 500 THEN 'medium'
  ELSE 'high'
END
```

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-dimension-sql-form.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=0d47d6614870d5e573dac3ece9c871b0" width="832" height="528" data-path="images/guides/custom-fields/custom-dimension-sql-form.png" />
</Frame>

And after you run your query, you will see your new custom dimension categorising your orders' totals:

<Frame>
  <img src="https://mintcdn.com/lightdash-mintlify-ca973f84/cHghj5I2wtqMZ-ik/images/guides/custom-fields/custom-dimension-sql-result.png?fit=max&auto=format&n=cHghj5I2wtqMZ-ik&q=85&s=eef2251fc258c60b17e571ce8cf7607f" width="1153" height="746" data-path="images/guides/custom-fields/custom-dimension-sql-result.png" />
</Frame>
