GA4 Calculated Metrics: Custom Formulas in Reports

A calculated metric lets you build a new GA4 metric from a formula, such as one revenue figure divided by another, and use it in reports, explorations and the Data API. This guide covers how to create one, the formula rules, the limits Google sets, cost and revenue restrictions, and when a calculated field in Data Studio is the simpler choice.

This guide uses Analytics Help: Create calculated metrics, About custom dimensions and metrics, Archive custom dimensions and metrics, Access and data-restriction management and Customize detail reports, plus Google's developer reference for the CalculatedMetric resource in the Admin API and the Data Studio page About calculated fields. Quotes are from those pages.

What a calculated metric is

Google defines calculated metrics as "metrics that combine one or more existing metrics and/or custom metrics within a mathematical formula to produce a new and potentially more valuable metric." Its own example is an Item margin metric, built "by combining the Item price standard metric and an Item COGS custom metric." The cost of goods would come from a custom metric you send yourself; the price is already in GA4 if you use ecommerce tracking.

The point, in Google's words, is that "you can adjust any metric to fit your business needs or logic. You can weight or discount existing metrics and create new metrics by combining standard and/or custom metrics." Once created, the metric sits next to the built-in ones: Google says you can access calculated metrics in reports, explorations, and the Google Analytics Data API.

A calculated metric does not collect anything new. It only does arithmetic on numbers GA4 already has. If the number you need is not collected yet, you first need an event parameter registered as a custom metric; that part is covered in our guide to GA4 custom dimensions and metrics.

Calculated metric, custom metric or calculated field

GA4 custom metricGA4 calculated metricData Studio calculated field
What it isA numeric event parameter you send and registerA formula over standard and custom metricsA formula over fields in one data source or chart
Collects new dataYesNoNo
Where it showsGA4 reports, explorations, APIGA4 reports, explorations, Data APIData Studio reports only
Limit per standard property505Not a GA4 quota
Limit per 360 property12550Not a GA4 quota

The GA4 limits are from Google's table in About custom dimensions and metrics. The Data Studio column is from the calculated fields page linked above.

Who can create one, and the limits

You "must be an editor or administrator to create a calculated metric." Other roles cannot add one.

  • Number: up to "5 calculated metrics per standard property" and "50 calculated metrics per 360 property."
  • No nesting: "You can't reference a calculated metric in the formula for another calculated metric. You can only use predefined metrics and custom metrics in the formula for a calculated metric."
  • Formula length: "Formulas are limited to 1024 characters."
  • Custom metrics per formula: the Admin API reference adds that the "Maximum number of unique referenced custom metrics is 5."

Five is not many on a standard property, so it pays to decide which ratios your team actually looks at before creating them. When you hit the limit, you archive one you no longer use; see archiving below for what that breaks.

Creating a calculated metric

  1. In Google Analytics, click Admin and make sure you are in the right property.
  2. Click Custom definitions.
  3. In the Calculated metrics tab, click Create calculated metric.
  4. Fill in the fields below, then click Save.
FieldWhat Google says about it
NameAppears in the metric selectors for reports. Must be unique across all calculated and custom metrics. You can change it later.
API nameFilled in from the name. You can change it during creation, "but you can't change the name once you create the calculated metric." Letters, numbers and underscores only; it must be unique, and becomes free to reuse if you archive the metric.
Description"The description is available in reports when hovering over the metric." Use it to say how the number is worked out.
FormulaMetric names in single curly brackets, numbers, decimals and operators (see the next section).
Unit of measurementDetermines how the calculated metric appears in reports.

Because the API name is fixed, choose it with care if anyone will pull the metric through the API or a dashboard connector: a short, plain name such as shipping_share is easier to live with than whatever GA4 generates from a long display name.

Formula rules

In the Formula field, "Start typing to see a list of predefined metrics you can use to define the formula. You can also enter numbers and decimals. Metric names must be surrounded by single curly brackets {}." The accepted operators are:

  • + addition
  • - subtraction, or a negative number
  • * multiplication
  • / division
  • ( ) parentheses, to set the order

The Help page lists no functions such as IF or ROUND, and no dimensions: the formula is arithmetic on metrics and numbers. Google's two worked examples on the Help page are:

  • Shipping percentage: {Shipping amount} / {Purchase revenue}
  • Item discount percentage: {Item discount amount} / {Item revenue}

The Admin API reference shows the same rules in API form, with metric API names instead of display names: "( customEvent:parameterName + cartPurchaseQuantity ) / 2.0". It also lists the units a calculated metric can have: standard, currency, feet, miles, meters, kilometers, milliseconds, seconds, minutes and hours.

Our suggestion: before you save, check the result against numbers you can work out by hand for a short date range in a standard report. A formula that divides by a metric that is sometimes zero, or mixes an event-level metric with an item-level one, can give rows that look odd; the check catches that early.

Using it in reports, explorations and the API

  • Reports: an editor or administrator adds it to a detail report through Customize report. Google allows "up to 12 metrics to a detail report", and you pick them with Add metric, where calculated metrics appear by name.
  • Explorations: add it from the metric list like any other metric; see our guide to GA4 explorations for building those reports.
  • Data API: the Admin API reference says the API name is "used when referencing this calculated metric from external APIs", in the form calcMetric:{calculatedMetricId}. Calculated metrics can also be created, listed, updated and deleted through the Admin API.

The Admin API also has a field called invalidMetricReference. If it is true, Google warns that "Anything using a calculated metric with invalidMetricReference set to true may fail, produce warnings, or produce unexpected results." If a report built on a calculated metric starts showing warnings, this flag is worth checking.

Cost and revenue data

GA4 lets an administrator give a user the No Cost Metrics or No Revenue Metrics restriction. Those restrictions reach calculated metrics too: the access page says cost and revenue metrics include "any metric derived from a cost or revenue metric." The Admin API marks each calculated metric with the types of restricted data it contains, cost data or revenue data, so GA4 knows which users may see it.

So a metric such as revenue per session is a revenue metric. A user with the No Revenue Metrics restriction will not see it, in the interface or through the API. Keep that in mind if you plan to share a ratio with a team or a contractor whose access you have limited.

Editing, copying and archiving

To edit, go to Admin, Custom definitions, the Calculated metrics tab, and click More, then Edit next to the metric. You can change the name, description, formula and unit of measurement. The same menu has Copy, which creates a version you can edit and save as a new calculated metric (it uses one of your slots).

Archiving is how you free a slot, and it is permanent. Google warns that "Archiving dimensions or metrics can't be undone and the corresponding dimensions or metrics can't be restored." What happens to things that use the archived metric:

  • Reports: they "become invalid until you remove the archived custom dimension or metric from the reports."
  • Explorations and segments: they "are invalid and will not load" until the archived definition is removed.
  • Audiences: an audience defined with it becomes invalid and "doesn't accumulate any new users."

While archiving you can export a CSV of everything affected. Do that first, so you know which reports to fix.

When a Data Studio calculated field is simpler

If the ratio is only needed on a dashboard, a calculated field in Data Studio may be enough. (Google's documentation now says "Looker Studio is now called Data Studio"; our Data Studio dashboard guide covers connecting GA4.) Google says calculated fields "can perform arithmetic and math; manipulate text, date, and geographical information; and use branching logic", which is more than a GA4 formula allows, and they are not limited by GA4's calculated metric quota.

A field made in the data source "is available in any report that uses that data source", but "You can't use a data source calculated field with blended data", and you need edit rights to the data source. The trade-off is that the field lives only in Data Studio: people who open GA4 itself will not see it.

Our suggestion: use a GA4 calculated metric for the handful of numbers your team checks inside GA4 and wants to read the same way everywhere, and keep one-off dashboard maths in Data Studio. Monthly reporting built on top of both is covered in website analytics reporting.

Frequently asked questions

How many calculated metrics can a GA4 property have?

Five per standard property and 50 per Analytics 360 property, according to Google's Help page.

Can a calculated metric use another calculated metric?

No. Google says you can only use predefined metrics and custom metrics in the formula.

Can I use dimensions or IF logic in the formula?

No. The formula accepts metrics in curly brackets, numbers, and the operators plus, minus, multiply, divide and parentheses. For conditional logic, a Data Studio calculated field is the option.

Who can create a calculated metric?

An editor or administrator on the property.

Can I rename a calculated metric?

The display name can be changed at any time. The API name can only be changed while you create the metric.

What happens when I archive one?

It cannot be restored. Reports, explorations, segments and audiences that use it become invalid until you remove it, and audiences stop adding new users.

Deciding which numbers are worth a calculated metric, and setting up the tracking behind them, is part of our website development work. See all our services, or email [email protected].