-
Notifications
You must be signed in to change notification settings - Fork 40
Feature/stripe mrr arr models #138
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
528f205
feature/stripe-mrr-arr-models
fivetran-savage 8cfb74e
add_price_plan_seed_data
fivetran-savage 00f748e
Update PR reference in CHANGELOG.md
fivetran-savage 0e5ff19
update_price_seed_data
fivetran-savage bcd3252
update CHANGELOG
fivetran-savage 4cf6395
dbt bump to v3.0.0 (#137)
fivetran-data-model-bot 9d4b6b6
continue rebase - resolve conflict
fivetran-savage 2077707
Update PR reference in CHANGELOG.md
fivetran-savage 5e3efc4
add-arr-to-analysis-folder
fivetran-savage 70d297a
update_folder_name
fivetran-savage ef514e9
Merge branch 'main' into feature/stripe-mrr-arr-models
fivetran-savage 765788a
update-project-yml
fivetran-savage 92904e6
add_config_to_analyses
fivetran-savage 23cd46e
update_changelog
fivetran-savage 577afa5
prerelease_update
fivetran-savage 6f66adf
add_new_model_to_quickstart
fivetran-savage 2f8af64
Generate dbt docs via GitHub Actions
github-actions[bot] df0172d
add_docs
fivetran-savage d6c16d9
remove_date_spine_dependency
fivetran-savage ee817d0
Update Stripe package version to 1.3.0-a4
fivetran-savage 7485ed4
add_cross_join_to_date_spine
fivetran-savage 6343924
Generate dbt docs via GitHub Actions
github-actions[bot] f5e512d
add_weekly_subscription_logic
fivetran-savage 0aec95a
add_price_plan_grain_to_mrr
fivetran-savage e92da7b
add_coupon_and_int_discount_model
fivetran-savage 6ae933e
correct_version
fivetran-savage 4fab22e
Merge remote-tracking branch 'origin/main' into feature/stripe-mrr-ar…
fivetran-savage a37a417
Cast recurring_interval_count to integer type
fivetran-savage ba77519
cast discount_amount as dbt.type_numeric
fivetran-savage aa21685
Fix discount_amount cast
fivetran-savage 7944982
update_version
fivetran-savage 1d3e7c2
incorporate_review_suggestions
fivetran-savage 60046da
Add 'coupon' feature to disable models section
fivetran-savage 9821457
update_changelog
fivetran-savage 0800ac1
remove_subscription_variable_from_subscription_item
fivetran-savage eb640c7
fix_variable_config_placement
fivetran-savage 1505af4
Generate dbt docs via GitHub Actions
github-actions[bot] d666c43
update_changelog
fivetran-savage 24be7b2
Incorporate review suggestions
fivetran-savage 024b26a
Update CHANGELOG.md
fivetran-savage fabb267
Update CHANGELOG.md
fivetran-savage 060bdf4
Update CHANGELOG
fivetran-savage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Stripe Analysis | ||
| > Note: The compiled sql within the analysis folder references the final model [stripe__subscription_item_mrr_report](https://github.com/fivetran/dbt_stripe/blob/master/models/stripe_financial_reports/stripe__subscription_item_mrr_report.sql). As such, prior to compiling the provided sql to roll MRR up to the customer level or analyze ARR metrics, you must first execute `dbt run`. | ||
|
|
||
|
|
||
| ## Analysis SQL | ||
| | **sql** | **description** | | ||
| | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | [stripe__arr_snapshot_analysis](https://github.com/fivetran/dbt_stripe/blob/master/analysis/stripe__arr_snapshot_analysis.sql) | The output of the compiled sql will generate a high-level ARR snapshot report for the entire business that can be used for revenue forecasting. The analysis provides year-end ARR metrics by aggregating MRR data from the last month of each calendar year and multiplying by 12. The SQL references the `stripe__subscription_item_mrr_report` model and aggregates metrics by currency. Subscriptions must be enabled for this report to compile correctly. | | ||
| | [stripe__customer_mrr_analysis](https://github.com/fivetran/dbt_stripe/blob/master/analysis/stripe__customer_mrr_analysis.sql) | The output of the compiled sql will generate an MRR report at the customer level of granularity that can be used for retention reporting and cohort analysis. The analysis aggregates monthly recurring revenue by customer and month, providing insights into customer-level revenue trends over time. The SQL references the `stripe__subscription_item_mrr_report` model. This report can also be generated at the overall business level by removing the customer_id field from the aggregation. | | ||
|
|
||
| ## SQL Compile Instructions | ||
| Leveraging the above sql is made possible by the [analysis functionality of dbt](https://docs.getdbt.com/docs/building-a-dbt-project/analyses/). In order to | ||
| compile the sql, you will perform the following steps: | ||
| - Execute `dbt run` to create the package models. | ||
| - Execute `dbt compile` to generate the target specific sql. | ||
| - Navigate to your project's `/target/compiled/stripe/analysis` directory. | ||
| - Copy the desired analysis code (`stripe__arr_snapshot_analysis` or `stripe__customer_mrr_analysis`) and run in your data warehouse. | ||
| - Confirm the revenue metrics match your expected subscription and billing patterns. | ||
| - Analyze the ARR snapshots and customer-level MRR trends to identify growth opportunities, retention patterns, and revenue forecasting insights. | ||
|
|
||
| ## Contributions | ||
| Don't see a compiled sql statement you would have liked to be included? Notice any bugs when compiling | ||
| and running the analysis sql? If so, we highly encourage and welcome contributions to this package! If interested, the best first step is [opening a feature request](https://github.com/fivetran/dbt_stripe/issues/new?template=feature-request.yml). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| {{ config(enabled=var('stripe__using_subscriptions', True)) }} | ||
|
|
||
| with mrr_by_item as ( | ||
| select * | ||
| from {{ ref('stripe__subscription_item_mrr_report') }} | ||
|
|
||
| ), | ||
|
|
||
| monthly_rollup as ( | ||
| select | ||
| source_relation, | ||
| subscription_month as recurring_rev_month, | ||
| subscription_year as recurring_rev_year, | ||
| currency, | ||
| sum(current_month_mrr) as total_mrr | ||
| from mrr_by_item | ||
| {{ dbt_utils.group_by(4) }} | ||
|
fivetran-savage marked this conversation as resolved.
Outdated
|
||
|
|
||
| ), | ||
|
|
||
| snapshots as ( | ||
| select | ||
| source_relation, | ||
| recurring_rev_month, | ||
| recurring_rev_year, | ||
| currency, | ||
| total_mrr, | ||
| total_mrr * 12 as total_arr, | ||
| row_number() over ( | ||
| partition by source_relation, recurring_rev_year, currency | ||
| order by recurring_rev_month desc | ||
| ) as month_number | ||
| from monthly_rollup | ||
|
|
||
| ), | ||
|
|
||
| final as ( | ||
| select | ||
| source_relation, | ||
| recurring_rev_year, | ||
| currency, | ||
| round(total_arr, 2) as total_arr | ||
| from snapshots | ||
| where month_number = 1 -- last month in that year | ||
|
|
||
| ) | ||
|
|
||
| select * | ||
| from final | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| {{ config(enabled=var('stripe__using_subscriptions', True)) }} | ||
|
|
||
| with item_mrr as ( | ||
| select * | ||
| from {{ ref('stripe__subscription_item_mrr_report') }} | ||
| ), | ||
|
|
||
| customer_mrr as ( | ||
| select | ||
| source_relation, | ||
| customer_id, | ||
| subscription_year, | ||
| subscription_month, | ||
| currency, | ||
| sum(current_month_mrr) as current_month_mrr, | ||
| sum(previous_month_mrr) as previous_month_mrr | ||
| from item_mrr | ||
| group by | ||
| 1,2,3,4,5 | ||
|
fivetran-savage marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| select | ||
| *, | ||
| case | ||
| when previous_month_mrr is null | ||
| and current_month_mrr > 0 then 'new' | ||
| when current_month_mrr > previous_month_mrr then 'expansion' | ||
| when previous_month_mrr > current_month_mrr | ||
| and current_month_mrr > 0 then 'contraction' | ||
| when (current_month_mrr = 0 or current_month_mrr is null) | ||
| and previous_month_mrr > 0 then 'churned' | ||
| when previous_month_mrr = 0 | ||
| and current_month_mrr > 0 then 'reactivation' | ||
| when current_month_mrr = previous_month_mrr then 'unchanged' | ||
| else 'unknown' | ||
| end as customer_mrr_type | ||
| from customer_mrr | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| id,_fivetran_synced,active,billing_scheme,created,currency,invoice_item_id,is_deleted,livemode,lookup_key,metadata,nickname,product_id,recurring_aggregate_usage,recurring_interval,recurring_interval_count,recurring_usage_type,tiers_mode,transform_quantity_divide_by,transform_quantity_round,type,unit_amount,unit_amount_decimal | ||
| price_1,2022-09-22 23:49:02,TRUE,per_unit,2020-05-02 19:21:44,usd,ii_FYFJSuzUa5YRk,FALSE,TRUE,,{},,prod_HCqb8lm6kfYk,,,,,,,,one_time,100000,100000 | ||
| price_1,2022-09-22 23:49:02,TRUE,per_unit,2020-05-02 19:21:44,usd,ii_FYFJSuzUa5YRk,FALSE,TRUE,,{},,prod_HCqb8lm6kfYk,,,,,,,,one_time,100000,100000 | ||
| price_2,2024-01-15 10:30:00,TRUE,per_unit,2023-06-01 12:00:00,usd,,FALSE,TRUE,,{},Basic Plan,prod_001,,month,1,licensed,,,,recurring,2999,2999 | ||
| price_3,2024-01-15 10:30:00,TRUE,per_unit,2023-07-15 14:30:00,usd,,FALSE,TRUE,,{},Annual Plan,prod_002,,year,1,licensed,,,,recurring,29990,29990 | ||
| price_4,2024-01-15 10:30:00,TRUE,per_unit,2023-08-20 09:15:00,eur,,FALSE,TRUE,,{},Quarterly Plan,prod_003,,month,3,licensed,,,,recurring,8000,8000 |
53 changes: 53 additions & 0 deletions
53
integration_tests/tests/consistency/consistency_subscription_item_mrr_report.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| {{ config( | ||
| tags="fivetran_validations", | ||
| enabled=var('fivetran_validation_tests_enabled', false) | ||
| ) }} | ||
|
|
||
| -- this test ensures the subscription_item_mrr_report end model matches the prior version | ||
| -- aggregated on the subscription_month, subscription_year, and source_relation grain | ||
|
fivetran-savage marked this conversation as resolved.
Outdated
|
||
| with | ||
| {% for prod_or_dev in ('prod', 'dev') %} | ||
| {% set cols = adapter.get_columns_in_relation(ref('stripe__subscription_item_mrr_report')) %} | ||
| {{ prod_or_dev }} as ( | ||
| select | ||
| subscription_month, | ||
| subscription_year, | ||
| source_relation | ||
| {% for col in cols if col.name not in ["subscription_item_id", "subscription_id", "customer_id", "product_id", "subscription_status", "currency", "subscription_month", "subscription_year", "source_relation", "item_month_number", "mrr_type"] %} | ||
| , floor(sum({{ col.name }})) as summed_{{ col.name }} -- floor and sum is to keep consistency between dev and prod aggs | ||
| {% endfor %} | ||
| from {{ target.schema }}_stripe_{{ prod_or_dev }}.stripe__subscription_item_mrr_report | ||
| group by 1,2,3 | ||
| ), | ||
| {% endfor %} | ||
|
|
||
| prod_not_in_dev as ( | ||
| -- rows from prod not found in dev | ||
| select * from prod | ||
| except distinct | ||
| select * from dev | ||
| ), | ||
|
|
||
| dev_not_in_prod as ( | ||
| -- rows from dev not found in prod | ||
| select * from dev | ||
| except distinct | ||
| select * from prod | ||
| ), | ||
|
|
||
| final as ( | ||
| select | ||
| *, | ||
| 'from prod' as source | ||
| from prod_not_in_dev | ||
|
|
||
| union all -- union since we only care if rows are produced | ||
|
|
||
| select | ||
| *, | ||
| 'from dev' as source | ||
| from dev_not_in_prod | ||
| ) | ||
|
|
||
| select * | ||
| from final | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.