Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

docs: metric math (#73745)

Alex Yarosh9b51f12817ed
diff --git a/docs/data-modeling/metrics.md b/docs/data-modeling/metrics.md
index f8a65afce79..d3d31fca1f0 100644
--- a/docs/data-modeling/metrics.md
+++ b/docs/data-modeling/metrics.md
@@ -87,9 +87,9 @@ To edit a metric:
3. Save your changes.
-## Explore and compare metrics
+## Explore, compare, and do math with metrics
-You can explore metrics, break them out by different dimensions, and compare metrics and [measures](../data-studio/measures.md) to each other in the [Metrics Explorer](../questions/metrics-explorer.md).
+To break metrics out by different dimensions, compare metrics and [measures](../data-studio/measures.md), and do math with metrics (like add or divide metrics by each other), check out the [Metrics Explorer](../questions/metrics-explorer.md).
![Metrics explorer](./images/metric-explorer.png)
@@ -113,7 +113,7 @@ You can use [custom expressions](../questions/query-builder/expressions.md) to d
(CountIf([Score] >= 9) - CountIf([Score] <= 6) ) / Count() * 100
```
-Metric formula must be an _aggregation_ of a column, meaning you can have a formula like `Sum([Price])` which will add up all the values in the `Price` column across all records, but you can't have a formula like `[Price] + [Tax]` which adds two values on a per-record basis. If you need to create a "calculated" column, consider using [transforms](../data-studio/transforms/transforms-overview.md) or [models](../data-modeling/models.md) instead.
+A metric formula must be an _aggregation_ of a column, meaning you can have a formula like `Sum([Price])` which will add up all the values in the `Price` column across all records, but you can't have a formula like `[Price] + [Tax]` which adds two values on a per-record basis. If you want to create a "calculated" column, consider creating a [transform](../data-studio/transforms/transforms-overview.md) or [model](../data-modeling/models.md) instead.
We don't recommend adding filters into the metric definition to avoid filter conflicts when using metrics in the query builder. You can use conditional custom expressions like [`CountIf`, `SumIf`, and `DistinctIf`](../questions/query-builder/expressions-list.md#aggregations) to create conditional aggregations.
diff --git a/docs/questions/images/break-out-metric.png b/docs/questions/images/break-out-metric.png
index effc2c2528b..ac430f4edc7 100644
Binary files a/docs/questions/images/break-out-metric.png and b/docs/questions/images/break-out-metric.png differ
diff --git a/docs/questions/images/breakout-chart-explorer.png b/docs/questions/images/breakout-chart-explorer.png
index 45afe8f4027..0d7cdc26abe 100644
Binary files a/docs/questions/images/breakout-chart-explorer.png and b/docs/questions/images/breakout-chart-explorer.png differ
diff --git a/docs/questions/images/compare-metrics.png b/docs/questions/images/compare-metrics.png
index 795b12c3f88..5d0aec12662 100644
Binary files a/docs/questions/images/compare-metrics.png and b/docs/questions/images/compare-metrics.png differ
diff --git a/docs/questions/images/math-with-metrics.png b/docs/questions/images/math-with-metrics.png
new file mode 100644
index 00000000000..9dedfcd5cdb
Binary files /dev/null and b/docs/questions/images/math-with-metrics.png differ
diff --git a/docs/questions/images/metrics-explorer.png b/docs/questions/images/metrics-explorer.png
index ff6361bc173..077c7f8cc7d 100644
Binary files a/docs/questions/images/metrics-explorer.png and b/docs/questions/images/metrics-explorer.png differ
diff --git a/docs/questions/images/two-metrics.png b/docs/questions/images/two-metrics.png
index b067e6d9b4c..9cfb1ec5c5f 100644
Binary files a/docs/questions/images/two-metrics.png and b/docs/questions/images/two-metrics.png differ
diff --git a/docs/questions/metrics-explorer.md b/docs/questions/metrics-explorer.md
index 4495cf9839b..998e2ccedaa 100644
--- a/docs/questions/metrics-explorer.md
+++ b/docs/questions/metrics-explorer.md
@@ -5,7 +5,7 @@ summary: Explore metrics and measures across dimensions and compare them side by
# Metrics explorer
-The metrics Explorer is a space for ad-hoc analysis of [metrics](../data-modeling/metrics.md) and [measures](../data-studio/measures.md)
+The metrics explorer is a space for ad-hoc analysis of [metrics](../data-modeling/metrics.md) and [measures](../data-studio/measures.md)
![Metrics explorer](../questions/images/metrics-explorer.png)
@@ -15,6 +15,7 @@ You can:
- [Explore metrics and measures along their dimensions](#explore-a-metric-or-a-measure)
- [Compare multiple metrics and measures](#compare-metrics-and-measures)
+- [Do math with metrics](#calculations-with-metrics-and-measures)
- [Break out by additional dimensions](#break-out-by-dimensions)
- [Filter each metric or measure](#filter-metrics-and-measures)
- Zoom into time periods
@@ -25,25 +26,42 @@ To share your metric explorations with people in your organization, you can copy
## Explore a metric or a measure
+In the metrics explorer, you can explore how a measure or metric varies across dimensions.
+
To open a **metric** in the Metrics Explorer:
1. Navigate to the metric's home page.
To get to the metric's home page, you can click on a metric from its collection, from the [metrics browser](../data-modeling/metrics.md#see-all-metrics), or from search.
-2. Click **Explore** in the top right corner to open the metrics explorer
+2. To view the metric in the explorer, click **Explore** in the top right corner.
+
+To return to the metric's home page, click the metric card in the search bar and select **Go to metric home page**.
+
+To open a **measure** in the metrics explorer:
-To get back to the metric's page from metrics explorer, right-click the metric card in the search bar and select **Go to metric home page**.
+1. Navigate to the measure in **Data studio > Tables > [Your table] > Measures**.
+2. Select your measure.
+3. On the measure's page, click **three dots** next to the measure's name and select **Explore**.
-To open a **measure** in the metrics explorer, go directly to `[your metabase URL]/explore` and type the measure's name in the search bar. To get back to the measure definition from metrics explorer, right-click the measure card in the search bar and select **Edit in Data Studio**.
+Once you open a measure or metric in the metrics explorer, Metabase will create tabs plotting the metric/measure along the most appropriate dimensions, as well as the **Totals** tab with the total result of the metric, without any dimensions applied.
+
+You can also [break out](#break-out-by-dimensions) a metric/measure by additional dimensions or [filter the metric/measure](#filter-metrics-and-measures).
## Compare metrics and measures
-To compare multiple metrics or measures, search for measure or metric you want to add in the search bar.
+To compare multiple metrics or measures:
+
+1. [Open one of the metrics/measures in the metrics explorer](#explore-a-metric-or-a-measure).
+2. Click the top search bar and search for another measure or metric you want to add.
-![Compare metrics](./images/compare-metrics.png)
+3. Press **Enter** or click **Run** in the search bar.
-You'll see the dimensions of the first metric/measure below the search bar. You can pick a dimension to break out the metrics/measures (for example, if you want to see how both Number of Orders and Revenue change by date, state, or product category).
+ ![Compare metrics](./images/compare-metrics.png)
+
+You can add the same metric/measure multiple times. This is useful if you want to [break out](#break-out-by-dimensions) or [filter](#filter-metrics-and-measures) the metric, while keeping the total trend visibile. For example, you might want to compare the trend of total revenue to the revenue of a single product category.
+
+Once you pick the metrics, you'll see the dimensions of the first metric/measure below the search bar. You can pick a dimension to compare metrics/measures (for example, if you want to see how both Number of Orders and Revenue change by date, state, or product category).
![Compare metrics](./images/two-metrics.png)
@@ -61,20 +79,22 @@ If your metrics/measures don't have shared dimensions, you'll need to select a d
When your metrics/measures don't have shared dimensions, Metabase has no way of knowing how the dimensions relate to each other, so it's on you to make sure the dimensions you pick make sense to compare!
+You can [filter](#filter-metrics-and-measures) or [break out](#break-out-by-dimensions) each metric/measure separately, or [do simple calculations with metrics/measures](#calculations-with-metrics-and-measures).
+
## Break out by dimensions
You can also break out each metric by additional dimensions. For example, you might want to compare overall revenue to the number of orders for each product category.
+![Break out](./images/breakout-chart-explorer.png)
+
To break out a metric or measure by additional dimensions:
-1. Right-click on the metric's card in the search bar.
+1. Click on the metric's card in the search bar.
2. Select **Break out**
![Break out by](./images/break-out-metric.png)
3. Choose the breakout dimension.
-![Break out](./images/breakout-chart-explorer.png)
-
-To remove the breakout, right-click on the measure/metric card again and select **Remove breakout**
+To remove the breakout, click on the measure/metric card in the search bar again and select **Remove breakout**.
## Filter metrics and measures
@@ -89,3 +109,17 @@ To add a filter to a metric or measure:
You'll see the filter added below the metric or measure's card in the search bar. To remove the filter, click the **X** on the filter's card.
![Filtered metric](./images/filtered-metric.png)
+
+## Calculations with metrics and measures
+
+You can use the four basic math operations (`+`,`-`,`*`,`/`) on metrics/measures in the metrics explorer. For example, you can explore how revenue per user, `Revenue / Active users`, changes with time.
+
+The metrics explorer is especially useful when metrics and measures are associated with different data sources, likeif you have a "Revenue" metric on the `Subscriptions` table and an "Active users" metric on the `Events` table. If you were to compare these metrics in the query builder, you'd have to wrangle their tables with joins, but the metrics explorer lets you compare these metrics by just typing out a formula.
+
+![Math with metrics](./images/math-with-metrics.png)
+
+To write an expression with metrics/measures, just start entering the formula into the search bar. You can use `+`,`-`,`*`,`/`, parentheses, numbers, or other metrics (including using the same metric multiple times). To visualize the results, just press Enter.
+
+To edit the expression, click on the expression's card in the search bar and click **Edit**.
+
+You can also rename your expressions. For example, you might want to rename your formula `Revenue / Active users` as `Per user revenue`. To rename the expression, click the expression's card in the search bar, click **Rename**, and type the new name.