From 97dafb870a244c0bc59d66f6921e1568742ea0be Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Wed, 17 Nov 2021 16:59:30 +1300 Subject: [PATCH 1/2] Add filter examples to metrics --- website/docs/docs/building-a-dbt-project/metrics.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/website/docs/docs/building-a-dbt-project/metrics.md b/website/docs/docs/building-a-dbt-project/metrics.md index 5eaf9314b24..66457306e94 100644 --- a/website/docs/docs/building-a-dbt-project/metrics.md +++ b/website/docs/docs/building-a-dbt-project/metrics.md @@ -86,6 +86,19 @@ metrics: | filters | A list of filters to apply before calculating the metric | See below | no | | meta | Arbitrary key/value store | {team: Finance} | no | +### Filters +Filters should be defined as a list of dictionaries that define predicates for the metric. Filters are ANDed together. If more complex filtering is required, users can (and should) push that logic down into the underlying model. + +```yml +filters: + - field: is_paying + value: true + + - field: ltv + operator: ">=" + value: 100 +``` + ### Why define metrics? **Use metric specifications in downstream tools.** Metrics are available to dbt's compilation context via the [`graph.metrics` variable](graph). They are included in [the manifest artifact](manifest-json) for downstream metadata consumption. From e2e8dc5d4aec8cdf3cfb5d586c920b3235f94e55 Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Sat, 4 Dec 2021 15:19:55 +1300 Subject: [PATCH 2/2] Act on feedback --- .../docs/building-a-dbt-project/metrics.md | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/website/docs/docs/building-a-dbt-project/metrics.md b/website/docs/docs/building-a-dbt-project/metrics.md index 66457306e94..8d88cd0b6e9 100644 --- a/website/docs/docs/building-a-dbt-project/metrics.md +++ b/website/docs/docs/building-a-dbt-project/metrics.md @@ -63,7 +63,15 @@ metrics: filters: - field: is_paying - value: true + operator: 'is' + value: 'true' + - field: lifetime_value + operator: '>=' + value: '100' + - field: company_name + operator: '!=' + value: "'Acme, Inc'" + meta: {} ``` @@ -87,16 +95,21 @@ metrics: | meta | Arbitrary key/value store | {team: Finance} | no | ### Filters -Filters should be defined as a list of dictionaries that define predicates for the metric. Filters are ANDed together. If more complex filtering is required, users can (and should) push that logic down into the underlying model. +Filters should be defined as a list of dictionaries that define predicates for the metric. Filters are combined using AND clauses. For more control, users can (and should) include the complex logic in the model powering the metric. + +Note that `value` must be defined as a string in YAML, because it will be compiled into queries as part of a string. If your filter's value needs to be surrounded in quotes inside the query, use `"'nested'"` quotes: ```yml -filters: - - field: is_paying - value: true - - - field: ltv - operator: ">=" - value: 100 + filters: + - field: is_paying + operator: 'is' + value: 'true' + - field: lifetime_value + operator: '>=' + value: '100' + - field: company_name + operator: '!=' + value: "'Acme, Inc'" ``` ### Why define metrics?