dbt-labs / dbt-semantic-interfaces

The shared semantic layer definitions that dbt-core and MetricFlow use.
Apache License 2.0
66 stars 13 forks source link

[Feature] Support referencing a metric in where filter #273

Closed Jstein77 closed 5 months ago

Jstein77 commented 5 months ago

Is this your first time submitting a feature request?

Describe the feature

Context

Some metrics require multiple aggregations or dependencies on other metrics. For example, Streamlit measures “super users” which is calculated as a distinct count of users who have 10+ active days in the last 70 days. Notion measures “activated spaces” which is calculated as a distinct count of spaces where at least two users have two active days within the first 7 days of space creation. Both of these metrics require dependencies on some aggregation in order to produce the end metric and MetricFlow has no path to supporting this today. This paradigm is sometimes called “metrics as dimensions” by our users where an aggregation is an input to the metric definition.

Our plan to support this enable referencing a metric in a filter.

The general interface update is:

Parameter Description Type
metric:filter The filter condition applied to a metric. Previously this required the “Dimension(’dim_name’”) object syntax. You would now be able to reference metric and list of group by parameters i.e “Metrics(metric='', group_by=[])” Required

For example in a metric config:

metrics:
  - name: The metric name
    type: Categorical or Time or Aggregation
    type_params: specific type params 
    filter: | ##The metric filter. Can now reference a metric and associated dimensions or 
    {{Metric('metric_name', group_by=['list of entities or dimensions])}}

In a CLI query:

mf query --metrics average_bookings --group-by metric_time --where "{{Metric('bookings', ['user'])}} >2"

Describe alternatives you've considered

No response

Who will this benefit?

No response

Are you interested in contributing this feature?

No response

Anything else?

No response

Jstein77 commented 5 months ago

@QMalcolm This is the proposed interface change for metrics as dimensions. Can you help us scope the LOE for this change?