[Feature] Support metric_time
in Metric Filters with Parent Query Granularity Inheritance
#1659
Open
3 tasks done
Labels
Is this your first time submitting a feature request?
Describe the feature
Summary
Enable the ability to specify
metric_time
as part of a metric filter so the filter joins on the same granularity of the parent metric. This ensures metric filters respect the time context of the query.Motivation
Currently, metric filters can reference a single entity or dimension, but they do not have a way to inherit the granularity of the query. This creates a core issue where the parent metric grouped by a time-granularity (e.g., mont), but the filter is based on "all time" data.
Calculating something like 'Product Usage by Paid Users group by Day/Week/Month' is not possible with the current filter implementation. SCDs are not a viable approach because they can't dynamically adjust to the query timeframe and add unnecessarily complex SQL logic to the compiled code.
By allowing
metric_time
to be included in metric filters, we can:metric_time
is explicitly included.Proposed Behavior
metric_time
is included in a metric filter group-by, the filter is applied using the same time granularity as the queried parent metric.metric_time
is not specified in the metric filter, existing behavior remains unchanged.metric_time
is included but the parent metric does not have a time dimension, it is silently ignored.Use Case Example
Consider the question "How many SMS Customers are sending Emails by month":
The data will change post-facto if an account starts sending emails because the filter is applied over all time. This yields a meaningless metric with historical values that constantly fluctuate.
By changing the filter to
{{ Metric('sum_emails_sent', group_by=['account_id','metric_time']) }} > 0
, this allows analytics to create a metric that is historically static and outputs the intended results of "How many Paid SMS accounts sent emails last June".Describe alternatives you've considered
Who will this benefit?
This will benefit any analyst who is using the Semantic Layer to create dashboards or uses core metrics as part of query filters.
Are you interested in contributing this feature?
Yes - PR 1658. Likely NOT production ready
Anything else?
No response
The text was updated successfully, but these errors were encountered: