Skip to content

[Bug] Time truncation with conversion metrics #1676

@wtremml18

Description

@wtremml18

Is this a new bug in metricflow?

  • I believe this is a new bug in metricflow
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When I query sl query --metrics 7d_conversion_metric --group-by metric_time__month, the monthly granularity overrides the conversion metric and everything is trunced within the calculation. This should not be the intended behavior.

We essentially want to produce 7 day conversion grouped at the monthly level. As an added bonus, we would also want to exclude accounts where the conversion period is incomplete (e.g., base time < today() - conversion window) [pretty easy from a filter perspective, but should be default behavior]

Here is a snippet of code produced from the sl query

INNER JOIN
          product_funnel_events product_funnel_events_src_10000
        ON
          (
            subq_11.account_id = product_funnel_events_src_10000.account_id
          ) AND (
            (
              subq_11.metric_time__month <= DATE_TRUNC('month', product_funnel_events_src_10000.first_event_time)
            ) AND (
              subq_11.metric_time__month > DATEADD(day, -7, DATE_TRUNC('month', product_funnel_events_src_10000.first_event_time))
            )
          )

You can see that the conversion granularity isn't being respected because of the monthly grouping

Here is the metric definition for additional context

  - name: activation_7d
    description: "Conversion rate from signup to activation in 7 days"
    type: conversion
    label: Visit to buy conversion rate (7-day window)
    type_params:
      conversion_type_params:
        entity: account_id
        base_measure:
          name: num_signups
          fill_nulls_with: 0
          join_to_timespine: true
          filter: |
            {{ Dimension('pk_onboarding_activation__website_status') }} = 'LIVE' 
            and {{ Dimension('pk_onboarding_activation__spam_flag') }} = false
        conversion_measure:
          name: num_accounts_activated #Change this to a Filter instead of CASE WHEN
          fill_nulls_with: 0
          join_to_timespine: true
        window: 7 days

The query should function more like this (intentionally different syntax for clarity)

SELECT
      DATE_TRUNC('month', signup_time) AS metric_time__month
      , count(distinct base.account_id) as num_signups
      , count(distinct case when datediff('day', signup_time, activation_time) <=7 then 1 else 0 end AS num_activations
      , num_activations / num_signups as activation_7d
    FROM base
    LEFT JOIN conversion
        ON base.account_id = conversion.account_id
        AND signup_time <= activation_time
        AND dateadd('day', 7, signup_time) > activation_time
        AND signup_time <= dateadd('day', -7, getdate()) -- or max date of available data

Expected Behavior

If the conversion granularity is "days", grouping by a different granularity shouldn't impact the conversion calculation. It should aggregate by the base metric's time dimension.

Steps To Reproduce

  1. Create conversion metric with 7 day conversion
  2. Query using --group_by metric_time__month --compile

Relevant log output

Environment

- OS: Mac
- dbt: dbt_cloud
- metricflow: CLI version 0.38.28

Which database are you using?

snowflake

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageTasks that need to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions