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

clarifies mf timespine & creates mini guide #6836

Open
wants to merge 29 commits into
base: current
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
674eb1e
add requirements
mirnawong1 Jan 28, 2025
7961004
add mini guide for mf timespine
mirnawong1 Jan 28, 2025
91247ad
add imgs
mirnawong1 Jan 28, 2025
d0768b0
fix links
mirnawong1 Jan 28, 2025
c278a82
Update mf-time-spine.md
mirnawong1 Jan 28, 2025
7145d14
remove dbt cloud
mirnawong1 Jan 28, 2025
15ec294
Merge branch 'clarify-timepsine' of github.com:dbt-labs/docs.getdbt.c…
mirnawong1 Jan 28, 2025
c879246
Merge branch 'current' into clarify-timepsine
mirnawong1 Jan 29, 2025
7f449bb
Update website/docs/guides/mf-time-spine.md
mirnawong1 Jan 30, 2025
64f114d
Update website/docs/guides/mf-time-spine.md
mirnawong1 Jan 30, 2025
5c67def
Merge branch 'current' into clarify-timepsine
mirnawong1 Jan 30, 2025
d027884
Merge branch 'current' into clarify-timepsine
mirnawong1 Feb 3, 2025
5c3af77
Merge branch 'current' into clarify-timepsine
mirnawong1 Feb 7, 2025
b57e449
remove unnecessary examples
mirnawong1 Feb 7, 2025
eab8830
package lock
mirnawong1 Feb 7, 2025
8ab5852
update timespine guide
mirnawong1 Feb 7, 2025
869efac
Merge branch 'current' into clarify-timepsine
mirnawong1 Feb 10, 2025
b3e28bb
Merge branch 'current' into clarify-timepsine
mirnawong1 Feb 11, 2025
a4d7706
Merge branch 'current' into clarify-timepsine
mirnawong1 Feb 27, 2025
2f51705
Merge branch 'current' into clarify-timepsine
mirnawong1 Feb 27, 2025
63e41d6
Update website/docs/guides/mf-time-spine.md
mirnawong1 Feb 27, 2025
98d2910
Update mf-time-spine.md
mirnawong1 Feb 27, 2025
5067891
Update website/docs/guides/mf-time-spine.md
mirnawong1 Feb 27, 2025
4fb4006
Update website/docs/guides/mf-time-spine.md
mirnawong1 Feb 27, 2025
eb62f06
Update website/docs/guides/mf-time-spine.md
mirnawong1 Feb 27, 2025
8ed072a
Update website/docs/guides/mf-time-spine.md
mirnawong1 Feb 27, 2025
eebc171
Update mf-time-spine.md
mirnawong1 Feb 27, 2025
fc3ed90
update mf tiemspine
mirnawong1 Feb 27, 2025
34c9eb9
Merge branch 'current' into clarify-timepsine
mirnawong1 Mar 3, 2025
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
40 changes: 38 additions & 2 deletions website/docs/docs/build/metricflow-time-spine.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,40 @@ 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 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 at least one dbt model which provides a time-spine, and then specify (in YAML) the columns to be used for time-based joins. MetricFlow will join against the time-spine model for the following types of metrics and dimensions:
To use MetricFlow with time-based metrics and dimensions, you _must_ provide a time spine table. This table serves as the foundation for time-based joins and aggregations. You can either:

- Create a time spine SQL table from scratch (check out the [example time spine tables](#example-time-spine-tables) section for examples), or
- Use an existing table in your project, like a `dim_date` table

And once you have a time spine table, you need to configure it in YAML to tell MetricFlow how to use it.

## Prerequisites
MetricFlow requires you to define at least one dbt model which provides a time-spine, and then specify (in YAML) the columns to be used for time-based joins. This means you need to:

- Define at least one [time spine table](#example-time-spine-tables) at the whichever granularity needed for your metrics (either daily or hourly). You can optionally define additional tables for coarser grains (like monthly or yearly).
- [Configure each time spine table in a YAML file](#configuring-time-spine-in-yaml) to define how MetricFlow recognizes and uses its columns.

MetricFlow will then join against the time spine model for the following types of metrics and dimensions:

- [Cumulative metrics](/docs/build/cumulative)
- [Metric offsets](/docs/build/derived#derived-metric-offset)
- [Conversion metrics](/docs/build/conversion)
- [Slowly Changing Dimensions](/docs/build/dimensions#scd-type-ii)
- [Metrics](/docs/build/metrics-overview) with the `join_to_timespine` configuration set to true

To see the generated SQL for the metric and dimension types that use time spine joins, refer to the respective documentation or add the `compile=True` flag when querying the Semantic Layer to return the compiled SQL.
To see the generated SQL for the metric and dimension types that use time spine joins, refer to the respective documentation or add the `compile=true` flag when querying the Semantic Layer to return the compiled SQL.

## Configuring time spine in YAML

:::tip Use our mini guide to create a time spine table
For a quick start guide on how to create a time spine table, check out our [MetricFlow time spine mini guide](/guides/mf-time-spine)!
:::

Time spine models are normal dbt models with extra configurations that tell dbt and MetricFlow how to use specific columns by defining their properties. Add the [`models` key](/reference/model-properties) for the time spine in your `models/` directory. If your project already includes a calendar table or date dimension, you can configure that table as a time spine. Otherwise, review the [example time-spine tables](#example-time-spine-tables) to create one. If the relevant model file doesn't exist, create it and add the configuration mentioned in the [next section](#creating-a-time-spine-table).

Some things to note when configuring time spine models:

- Make sure you already have a time spine SQL table defined in your project.
- Add the configurations under the `time_spine` key for that [model's properties](/reference/model-properties), just as you would add a description or tests.
- 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.
Expand Down Expand Up @@ -145,6 +163,13 @@ Note that if you're migrating from a `metricflow_time_spine.sql` file:

## Example time spine tables

The following examples show how to create time spine tables at different granularities:

- [Daily](#daily)
- [Daily (BigQuery)](#daily-bigquery)
- [Hourly](#hourly)


### Daily

<File name="metricflow_time_spine.sql">
Expand Down Expand Up @@ -333,6 +358,11 @@ You only need to include the `date_day` column in the table. MetricFlow can hand

## Custom calendar <Lifecycle status="Preview"/>

:::tip
Check out our mini guide on [how to create a time spine table](/guides/mf-time-spine) to get started!
:::


<VersionBlock lastVersion="1.8">

The ability to configure custom calendars, such as a fiscal calendar, is available now in [the "Latest" release track in dbt Cloud](/docs/dbt-versions/cloud-release-tracks), and it will be available in [dbt Core v1.9+](/docs/dbt-versions/core-upgrade/upgrading-to-v1.9).
Expand Down Expand Up @@ -385,3 +415,9 @@ models:
Note that features like calculating offsets and period-over-period will be supported soon!

</VersionBlock>


## Related docs

- [MetricFlow time granularity](/docs/build/dimensions?dimension=time_gran#time)
- [MetricFlow time spine mini guide](/guides/mf-time-spine)
Loading
Loading