-
Notifications
You must be signed in to change notification settings - Fork 977
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'current' into mwong-model-names
- Loading branch information
Showing
10 changed files
with
81 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ pagination_next: "docs/build/cumulative" | |
|
||
Once you've created your semantic models, it's time to start adding metrics! Metrics can be defined in the same YAML files as your semantic models, or split into separate YAML files into any other subdirectories (provided that these subdirectories are also within the same dbt project repo) | ||
|
||
The keys for metrics definitions are: | ||
The keys for metrics definitions are: | ||
|
||
| Parameter | Description | Type | | ||
| --------- | ----------- | ---- | | ||
|
@@ -22,7 +22,6 @@ The keys for metrics definitions are: | |
| `filter` | You can optionally add a filter string to any metric type, applying filters to dimensions, entities, or time dimensions during metric computation. Consider it as your WHERE clause. | Optional | | ||
| `meta` | Additional metadata you want to add to your metric. | Optional | | ||
|
||
|
||
Here's a complete example of the metrics spec configuration: | ||
|
||
```yaml | ||
|
@@ -39,14 +38,7 @@ metrics: | |
null | ||
``` | ||
This page explains the different supported metric types you can add to your dbt project. | ||
<!-- | ||
- [Cumulative](#cumulative-metrics) — Cumulative metrics aggregate a measure over a given window. | ||
- [Derived](#derived-metrics) — An expression of other metrics, which allows you to do calculations on top of metrics. | ||
- [Expression](#expression-metrics) — Allow measures to be modified using a SQL expression. | ||
- [Measure proxy](#measure-proxy-metrics) — Metrics that refer directly to one measure. | ||
- [Ratio](#ratio-metrics) — Create a ratio out of two measures. | ||
--> | ||
This page explains the different supported metric types you can add to your dbt project. | ||
### Conversion metrics <Lifecycle status='new'/> | ||
|
@@ -55,10 +47,11 @@ This page explains the different supported metric types you can add to your dbt | |
```yaml | ||
metrics: | ||
- name: The metric name # Required | ||
description: the metric description # Optional | ||
description: The metric description # Optional | ||
type: conversion # Required | ||
label: # Required | ||
type_params: # Required | ||
fills_nulls_with: Set the value in your metric definition instead of null (such as zero) # Optional | ||
conversion_type_params: # Required | ||
entity: ENTITY # Required | ||
calculation: CALCULATION_TYPE # Optional. default: conversion_rate. options: conversions(buys) or conversion_rate (buys/visits), and more to come. | ||
|
@@ -82,9 +75,10 @@ metrics: | |
- [email protected] | ||
type: cumulative | ||
type_params: | ||
fills_nulls_with: 0 | ||
measures: | ||
- distinct_users | ||
#Omitting window will accumulate the measure over all time | ||
# Omitting window will accumulate the measure over all time | ||
window: 7 days | ||
|
||
``` | ||
|
@@ -100,6 +94,7 @@ metrics: | |
type: derived | ||
label: Order Gross Profit | ||
type_params: | ||
fills_nulls_with: 0 | ||
expr: revenue - cost | ||
metrics: | ||
- name: order_total | ||
|
@@ -139,6 +134,7 @@ metrics: | |
# Define the metrics from the semantic manifest as numerator or denominator | ||
type: ratio | ||
type_params: | ||
fills_nulls_with: 0 | ||
numerator: cancellations | ||
denominator: transaction_amount | ||
filter: | # add optional constraint string. This applies to both the numerator and denominator | ||
|
@@ -157,6 +153,7 @@ metrics: | |
filter: | # add optional constraint string. This applies to both the numerator and denominator | ||
{{ Dimension('customer__country') }} = 'MX' | ||
``` | ||
|
||
### Simple metrics | ||
|
||
[Simple metrics](/docs/build/simple) point directly to a measure. You may think of it as a function that takes only one measure as the input. | ||
|
@@ -171,6 +168,7 @@ metrics: | |
- name: cancellations | ||
type: simple | ||
type_params: | ||
fills_nulls_with: 0 | ||
measure: cancellations_usd # Specify the measure you are creating a proxy for. | ||
filter: | | ||
{{ Dimension('order__value')}} > 100 and {{Dimension('user__acquisition')}} | ||
|
@@ -187,6 +185,7 @@ filter: | | |
filter: | | ||
{{ TimeDimension('time_dimension', 'granularity') }} | ||
``` | ||
|
||
### Further configuration | ||
|
||
You can set more metadata for your metrics, which can be used by other tools later on. The way this metadata is used will vary based on the specific integration partner | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ Ratio allows you to create a ratio between two metrics. You simply specify a num | |
| `denominator` | The name of the metric used for the denominator, or structure of properties. | Required | | ||
| `filter` | Optional filter for the numerator or denominator. | Optional | | ||
| `alias` | Optional alias for the numerator or denominator. | Optional | | ||
| `fill_nulls_with` | Set the value in your metric definition instead of null (such as zero). | Optional | | ||
|
||
The following displays the complete specification for ratio metrics, along with an example. | ||
|
||
|
@@ -31,6 +32,7 @@ metrics: | |
type: ratio # Required | ||
label: The value that will be displayed in downstream tools #Required | ||
type_params: # Required | ||
fill_nulls_with: Set value instead of null (such as zero) # Optional | ||
numerator: The name of the metric used for the numerator, or structure of properties # Required | ||
name: Name of metric used for the numerator # Required | ||
filter: Filter for the numerator # Optional | ||
|
@@ -50,40 +52,41 @@ metrics: | |
label: Food Order Ratio | ||
type: ratio | ||
type_params: | ||
fill_nulls_with: 0 | ||
numerator: food_orders | ||
denominator: orders | ||
|
||
``` | ||
## Ratio metrics using different semantic models | ||
The system will simplify and turn the numerator and denominator in a ratio metric from different semantic models by computing their values in sub-queries. It will then join the result set based on common dimensions to calculate the final ratio. Here's an example of the SQL generated for such a ratio metric. | ||
```sql | ||
select | ||
subq_15577.metric_time as metric_time | ||
, cast(subq_15577.mql_queries_created_test as double) / cast(nullif(subq_15582.distinct_query_users, 0) as double) as mql_queries_per_active_user | ||
subq_15577.metric_time as metric_time, | ||
cast(subq_15577.mql_queries_created_test as double) / cast(nullif(subq_15582.distinct_query_users, 0) as double) as mql_queries_per_active_user | ||
from ( | ||
select | ||
metric_time | ||
, sum(mql_queries_created_test) as mql_queries_created_test | ||
metric_time, | ||
sum(mql_queries_created_test) as mql_queries_created_test | ||
from ( | ||
select | ||
cast(query_created_at as date) as metric_time | ||
, case when query_status in ('PENDING','MODE') then 1 else 0 end as mql_queries_created_test | ||
cast(query_created_at as date) as metric_time, | ||
case when query_status in ('PENDING','MODE') then 1 else 0 end as mql_queries_created_test | ||
from prod_dbt.mql_query_base mql_queries_test_src_2552 | ||
) subq_15576 | ||
group by | ||
metric_time | ||
) subq_15577 | ||
inner join ( | ||
select | ||
metric_time | ||
, count(distinct distinct_query_users) as distinct_query_users | ||
metric_time, | ||
count(distinct distinct_query_users) as distinct_query_users | ||
from ( | ||
select | ||
cast(query_created_at as date) as metric_time | ||
, case when query_status in ('MODE','PENDING') then email else null end as distinct_query_users | ||
cast(query_created_at as date) as metric_time, | ||
case when query_status in ('MODE','PENDING') then email else null end as distinct_query_users | ||
from prod_dbt.mql_query_base mql_queries_src_2585 | ||
) subq_15581 | ||
group by | ||
|
@@ -115,6 +118,7 @@ metrics: | |
- [email protected] | ||
type: ratio | ||
type_params: | ||
fill_nulls_with: 0 | ||
numerator: | ||
name: distinct_purchasers | ||
filter: | | ||
|
@@ -124,4 +128,7 @@ metrics: | |
name: distinct_purchasers | ||
``` | ||
Note the `filter` and `alias` parameters for the metric referenced in the numerator. Use the `filter` parameter to apply a filter to the metric it's attached to. The `alias` parameter is used to avoid naming conflicts in the rendered SQL queries when the same metric is used with different filters. If there are no naming conflicts, the `alias` parameter can be left out. | ||
Note the `filter` and `alias` parameters for the metric referenced in the numerator. | ||
- Use the `filter` parameter to apply a filter to the metric it's attached to. | ||
- The `alias` parameter is used to avoid naming conflicts in the rendered SQL queries when the same metric is used with different filters. | ||
- If there are no naming conflicts, the `alias` parameter can be left out. |
Oops, something went wrong.