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

[Bug] <title> #1676

Open
2 tasks done
wtremml18 opened this issue Feb 20, 2025 · 0 comments
Open
2 tasks done

[Bug] <title> #1676

wtremml18 opened this issue Feb 20, 2025 · 0 comments
Labels
bug Something isn't working triage Tasks that need to be triaged

Comments

@wtremml18
Copy link

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

@wtremml18 wtremml18 added bug Something isn't working triage Tasks that need to be triaged labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Tasks that need to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant