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

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

Closed
3 tasks done
Jstein77 opened this issue Mar 13, 2024 · 1 comment · Fixed by #274
Closed
3 tasks done

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

Jstein77 opened this issue Mar 13, 2024 · 1 comment · Fixed by #274
Assignees
Labels

Comments

@Jstein77
Copy link

Jstein77 commented Mar 13, 2024

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward change to existing dbt-semantic-interfaces functionality, rather than a Big Idea better suited to a discussion

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 Jstein77 added the enhancement New feature or request label Mar 13, 2024
@courtneyholcomb courtneyholcomb self-assigned this Mar 13, 2024
@Jstein77
Copy link
Author

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

courtneyholcomb added a commit that referenced this issue Mar 19, 2024
Resolves #273
Resolves SL-1849

<!---
Include the number of the issue addressed by this PR above if
applicable.
  PRs for code changes without an associated issue *will not be merged*.
  See CONTRIBUTING.md for more information.
-->

### Description
Allow users to reference metrics in where filters for metrics, measures,
and saved queries. This uses syntax like:
`{{ Metric('metric_name', group_by=['entity_name', 'dimension_name']) }}
= 10`
This unlocks new types of metrics that users have been asking for. Some
examples can be found in the linked issue and in [this design
doc](https://www.notion.so/dbtlabs/Metrics-as-Dimensions-55718e9516a7462787ffd6e3e8c1237e?pvs=4).

### Checklist

- [x] I have read [the contributing
guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md)
and understand what's expected of me
- [x] I have signed the
[CLA](https://docs.getdbt.com/docs/contributor-license-agreements)
- [x] This PR includes tests, or tests are not required/relevant for
this PR
- [x] I have run `changie new` to [create a changelog
entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry)
courtneyholcomb added a commit that referenced this issue Mar 19, 2024
Resolves #273
Resolves SL-1849

<!---
Include the number of the issue addressed by this PR above if
applicable.
  PRs for code changes without an associated issue *will not be merged*.
  See CONTRIBUTING.md for more information.
-->

### Description
Allow users to reference metrics in where filters for metrics, measures,
and saved queries. This uses syntax like:
`{{ Metric('metric_name', group_by=['entity_name', 'dimension_name']) }}
= 10`
This unlocks new types of metrics that users have been asking for. Some
examples can be found in the linked issue and in [this design
doc](https://www.notion.so/dbtlabs/Metrics-as-Dimensions-55718e9516a7462787ffd6e3e8c1237e?pvs=4).

### Checklist

- [x] I have read [the contributing
guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md)
and understand what's expected of me
- [x] I have signed the
[CLA](https://docs.getdbt.com/docs/contributor-license-agreements)
- [x] This PR includes tests, or tests are not required/relevant for
this PR
- [x] I have run `changie new` to [create a changelog
entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants