Skip to content

Commit

Permalink
clarify metrics key location
Browse files Browse the repository at this point in the history
this pr tries to clarify that metrics can be defined in their own standalone file or with in the semantic_models file (but not nested).

this was raised in by docs and user error in [community slack](https://getdbt.slack.com/archives/C02CCBBBR1D/p1737248111053329)
  • Loading branch information
mirnawong1 authored Jan 22, 2025
1 parent caeae60 commit 73ea818
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions website/docs/docs/build/metrics-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ tags: [Metrics, Semantic Layer]
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).
After building [semantic models](/docs/build/semantic-models), it's time to start adding metrics. This page explains the different supported metric types you can add to your dbt project

This article explains the different supported metric types you can add to your dbt project. The keys for metrics definitions are:
Metrics can be defined in the same YAML files as your semantic models, or defined in their dedicated separate YAML files located in any subdirectories within the same dbt project repository.

The keys for metrics definitions are:

<!-- for v1.8 and higher -->

Expand Down Expand Up @@ -107,7 +109,10 @@ It's possible to define a default time granularity for metrics if it's different
The granularity can be set using the `time_granularity` parameter on the metric, and defaults to `day`. If day is not available because the dimension is defined at a coarser granularity, it will default to the defined granularity for the dimension.

### Example
You have a semantic model called `orders` with a time dimension called `order_time`. You want the `orders` metric to roll up to `monthly` by default; however, you want the option to look at these metrics hourly. You can set the `time_granularity` parameter on the `order_time` dimension to `hour`, and then set the `time_granularity` parameter in the metric to `month`.
- You have a semantic model called `orders` with a time dimension called `order_time`.
- You want the `orders` metric to roll up to `monthly` by default; however, you want the option to look at these metrics hourly.
- You can set the `time_granularity` parameter on the `order_time` dimension to `hour`, and then set the `time_granularity` parameter in the metric to `month`.

```yaml
semantic_models:
...
Expand All @@ -130,6 +135,9 @@ metrics:
name: orders
time_granularity: month -- Optional, defaults to day
```

Remember that metrics can be defined in the same YAML files as your semantic models but must be defined as a separate top-level section and not nested within a `semantic_model`. Or you can define metrics in their dedicated separate YAML files located in any subdirectories within the same dbt project repository.

</VersionBlock>

## Conversion metrics
Expand Down

0 comments on commit 73ea818

Please sign in to comment.