Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter examples to metrics #915

Merged
merged 3 commits into from
Jan 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions website/docs/docs/building-a-dbt-project/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

@runleonarun runleonarun Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @joellabes just some fly by questions here!

Filters are ANDed together

Does this mean that when you provide multiple filters they will use AND logic, meaning all criteria must be met? It might help newer users and users who aren't native English speakers to expand this sentence just a bit! (Although I do appreciate how efficient this sentence is. ❤️ )

...pushing that logic down into the underlying model.

I'm also curious about this phrase. Do we talk more anywhere on how to do this? Can we link people to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that when you provide multiple filters they will use AND logic

Yep! happy to have it changed to anything else - none of this is my writing so I'm even less precious about it than normal 😉

I'm also curious about this phrase
Basically, instead of trying to implement more complex filters in the metric definition, we're expecting people to do their complex filtering inside of the model (in this example, ref('dim_customers')). I don't know if there's prior art we can link people out to :(


```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.
Expand Down