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

# Create a metric for your funnel

> Build formulas for approval rate, units per order, or profit per visit, then validate their format and calculation scope.

Use a custom metric when the built-in columns do not express the question you need to answer. For example, **CV** measures conversions per visit. If Event 1 is a submitted lead and Event 2 is an approved lead, your approval rate needs a different denominator.

Custom formulas calculate from the numeric metrics in each report row. They also calculate on the totals row, using its totals. They do not define a new incoming event or change which events count as conversions.

## Build an approval rate

Suppose your report contains 40 submitted leads in Event 1 and 12 approved leads in Event 2. The approval rate is `12 / 40 × 100 = 30%`.

1. Open the report's metrics selector.
2. Find **Custom metrics** and click **Add custom metric**.
3. Enter `approval_rate` as **Identifier**.
4. Enter this **Formula**:

```text theme={null}
ifnull(event2 / event1 * 100, 0)
```

5. Choose **Percent** and click **Add metric**.
6. Display **Event 1** and **Event 2** alongside the new column.
7. Check that the example row displays 30%.

The `ifnull` fallback returns zero when division produces a non-finite value, such as a zero denominator. This keeps the display usable, but zero submissions still means there is no approval-rate evidence.

Only use this formula when Event 1 and Event 2 have those meanings in the campaign being analyzed. Combining campaigns with different event mappings can create a mathematically valid but misleading percentage.

## Choose the right display type

| Type         | What the formula should return              | Example                                                     |
| ------------ | ------------------------------------------- | ----------------------------------------------------------- |
| **Number**   | The number you want displayed               | `ifnull(value1 / event1, 0)` for units per order event      |
| **Percent**  | The percentage number itself                | `30` displays as 30%                                        |
| **Currency** | A monetary amount in the report's USD basis | `ifnull((revenue - cost) / visits, 0)` for profit per visit |

Custom Percent formatting does not multiply by 100. Include `* 100` when the formula divides one count by another. For example, `event2 / event1` returns `0.3`, which would display as 0.3%, not 30%.

Built-in rates use fractional API values, so a custom formula displaying built-in CV as a percentage would use `cv * 100`.

## Use metric keys and supported arithmetic

Formulas use the case-sensitive keys from the [metric dictionary](/reports/metrics), such as `visits`, `lpclicks`, `uniqueVisits`, `revenue`, `cost`, and `event2`. A UI label such as `Clicks` is not the formula key `lpclicks`.

Use a clear identifier beginning with a letter or underscore and containing letters, numbers, or underscores. Choose a name that does not collide with an existing metric or a function. Adding the same custom identifier again replaces its definition.

Supported syntax includes numbers, parentheses, unary plus or minus, and the operators `+`, `-`, `*`, `/`, and `%`. Here `%` means remainder, not percentage formatting.

Supported functions are `abs`, `ceil`, `floor`, `max`, `min`, `pow`, `round`, `sqrt`, and `ifnull`. Use `pow(x, 2)` for a square. JavaScript property calls such as `Math.round(...)`, comparisons, and conditional expressions are not supported.

## Validate with a row you can calculate yourself

For 1,000 visits, USD 300 revenue, and USD 100 cost:

```text theme={null}
ifnull((revenue - cost) / visits, 0)
```

should return USD 0.20 with Currency formatting. For four order events with a combined `value1` of 12, `ifnull(value1 / event1, 0)` should return three units per order event.

Check both a normal row and a row with a zero denominator. Invalid formulas and non-finite results can display as zero, so a column of zeros is not proof that the formula is correct. Confirm metric spelling, supported syntax, and the underlying input columns.

## Know where the definition lives

Custom metrics are saved in this browser's local storage. They are not shared account definitions and are not automatically registered as metrics in the public reports API. Keep the formula separately if teammates or an external analysis need to reproduce it.

Sorting a custom metric orders the rows currently loaded in the browser. It does not request a complete server-side ranking by that formula. For a full external ranking, retrieve the complete [report dataset](/api-reference/reports-and-events), calculate the formula, and sort that dataset.

Use the remove control in the metrics selector when a definition is no longer needed. Removing it does not change stored tracking data.
