Time Metrics is currently in Beta. Contact support@honeydew.ai to activate it for your account.
Introduction
Defining how metrics relate to time is a common modeling need. The time metrics framework allows to build time-aware metrics. Time awareness allows:- Filling in missing dates when data is incomplete (i.e. when counting events for a particular day, should count 0 if the day has no events at all).
- Comparing time periods (i.e. current month event count vs previous month)
- Building period-to-date aggregations (i.e. a year-to-date total count metric)
Connecting Entities to Time
Entities in Honeydew can be connected to a time spine on a default date field. Once connected, all metrics on the entity operate in relation to the default date field:- Dates missing in the default date field will be filled
- Time offsets and period-to-date calculations in the entity will be relative to the default date field.
Example
When thelineitem entity is not connected to a time spine, metrics operating on it can’t relate to date.
For example, quantity by year will yield
However once the
lineitem entity is connected to a time spine then
its metrics become time aware.
For example, can add the lineitem.l_shipdate field as a default date field for lineitem:
sum_qty metric will be counted by shipping date:
Default date field will use the grain defined in the referenced field.
Time Metrics
This creates a time metric from an aggregation:- expression: either a Honeydew metric or aggregation expression. Must not include a GROUP BY.
- offset: based on Snowflake interval expression syntax, sets a negative interval to offset the grain. Note that if has a higher grain than the chosen
grain(i.e. a week interval on a monthly metric) it might get truncated to the chosen grain. - grain: based on Snowflake date or time part syntax - day/week/month/quarter/year. Sets the minimal grain of a metric.
- date_field: a field that is used to join to the time spine. When combined with
graina date_field is truncated to the grain. - date_range_start, date_range_end: a pair of fields that are used to join to the time spine.
date_field or date_range_*) set.
date_range_start and date_field fields are mutually exlcusive.Example
Consider the following metricsum_qty in lineitem entity:
date.
However sum_qty is not a time metric.
A query that groups it by date.year will have a result such as
A regular metric does not know how to relate to a time spine, thus will receive NULL as is the value for date fields.
sum_qty_when_shipped, that counts shipped quantity, is built of top of it
date will be done by joining it to the l_shipdate column, attributing all quantity to the shipping date
However, a different metric
sum_qty_when_received may count quantity to be shipped by counting quantity on the date an order was received:
May also use time metrics to look at a previous time period. For example, the following metric
sum_qty_when_shipped_prev_year
This can be used for YoY growth calculations (note to coalesce the null to zero).
Composing Time Metrics
Combining qualifiers
It is possible to compose time metrics by combining qualifiers, i.e.date_field and grain set.