Skip to content

Commit

Permalink
Update metricflow-time-spine.md
Browse files Browse the repository at this point in the history
adding clarifiation based on [thread in slack](https://dbt-labs.slack.com/archives/C03KHQRQUBX/p1726597063492349)
  • Loading branch information
mirnawong1 committed Sep 19, 2024
1 parent 39c0256 commit a35e613
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions website/docs/docs/build/metricflow-time-spine.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ sidebar_label: "MetricFlow time spine"
tags: [Metrics, Semantic Layer]
---

It's common in analytics engineering to have a date dimension or "time spine" table as a base table for different types of time-based joins and aggregations. The structure of this table is typically a base column of daily or hourly dates, with additional columns for other time grains, like fiscal quarter, defined based on the base column. You can join other tables to the time spine on the base column to calculate metrics like revenue at a point in time, or to aggregate to a specific time grain.
It's common in analytics engineering to have a date dimension or "time spine" table as a base table for different types of time-based joins and aggregations. The structure of this table is typically a base column of daily or hourly dates, with additional columns for other time grains, like fiscal quarters, defined based on the base column. You can join other tables to the time spine on the base column to calculate metrics like revenue at a point in time, or to aggregate to a specific time grain.

MetricFlow requires you to define a time spine table as a project level configuration, which then is used for various time-based joins and aggregations, like cumulative metrics. At a minimum, you need to define a time spine table for a daily grain. You can optionally define a time spine table for a different granularity, like hourly.
MetricFlow requires you to define a time spine table as a project-level configuration for time-based joins and aggregations, like cumulative metrics. You only need to configure time spine models that the Semantic Layer should recognize. At a minimum, define a time spine table for a daily grain. You can optionally define a time spine table for a different granularity, like hourly. Note that if you don’t have a date or calendar model in your project, you'll need to create one.

If you already have a date dimension or time spine table in your dbt project, you can point MetricFlow to this table by updating the `model` configuration to use this table in the Semantic Layer. For example, given the following directory structure, you can create two time spine configurations, `time_spine_hourly` and `time_spine_daily`.
If you already have a date dimension or time spine table in your dbt project, you can point MetricFlow to this table by updating the `model` configuration to use this table in the Semantic Layer. This is a model-level configuration that tells dbt to use the model for time range joins in the Semantic Layer.

For example, given the following directory structure, you can create two time spine configurations, `time_spine_hourly` and `time_spine_daily`. MetricFlow supports granularities ranging from milliseconds to years, refer to the [Dimensions page](/docs/build/dimensions#time?dimension=time_granularity) to find the full list of supported granularities.

:::tip
Previously, you were required to create a model called `metricflow_time_spine` in your dbt project. This is no longer required. However, you can build your time spine model from this table if you don't have another date dimension table you want to use in your project.
Expand Down Expand Up @@ -38,6 +40,8 @@ models:
```
</File>
For an example project, refer to our [Jaffle shop](https://github.com/dbt-labs/jaffle-sl-template/blob/main/models/marts/_models.yml) example.
Now, break down the configuration above. It's pointing to a model called `time_spine_daily`. It sets the time spine configurations under the `time_spine` key. The `standard_granularity_column` is the lowest grain of the table, in this case, it's hourly. It needs to reference a column defined under the columns key, in this case, `date_hour`. Use the `standard_granularity_column` as the join key for the time spine table when joining tables in MetricFlow. Here, the granularity of the `standard_granularity_column` is set at the column level, in this case, `hour`.


Expand Down

0 comments on commit a35e613

Please sign in to comment.