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

(Demo) Fix: customer lifetime value calculation in customers #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

even-wei
Copy link
Collaborator

@even-wei even-wei commented Nov 27, 2023

👋 This is a demo pull request of dbt model changes, powered by Recce to provide proof of correctness during development and change review.
This is still early and we'd love your feedback!

Description & motivation

The customer lifetime value (CLV) in customers model incorrectly included orders that were not yet completed, leading to potentially inaccurate business insights.
I modified the CLV calculation within customers to consider only "completed" orders.

To-do before merge

Notify Stakeholders

  • Ask Sarah to review the customer segment impacts on marketing (see impact section below)

Lineage:

Lineage DAG Diff

image

Modified customers model to adjust customer_lifetime_value calculation.

 


Validation of models:

As expected, the customer lifetime value has changed. The average value of CLV has been reduced and this affects 98% of customers.

Query Diff: customers

image

The customer_lifetime_value has reduced for certain customers. This is expected given the change to the CLV calculation.

 


Profile Diff: customers

image

Min/max remains unchanged, average value has dropped from 2758.6 to 1871.76 as expected.

 


Value Diff: customers

image

Only 1.19% match on customer_lifetime_value.

 


Magic metric of customers

image

Our magic metric, average lifetime value, goes down as well.

SQL

SELECT
    DATE_TRUNC('week', first_order) AS first_order_week,
    AVG(customer_lifetime_value) AS avg_lifetime_value
FROM
    {{ ref("customers") }}
WHERE first_order is not NULL    
GROUP BY
    first_order_week
ORDER BY
    first_order_week;

Impact considerations:

The adjustment to CLV values has resulted in 26.45% change of customer ‘value segment’. This impact is also expected.

Value Diff: customer_segments

image

customer_lifetime_value as expected matches parent table at 1.19%.
value_segment is changed by 26.45%.

 


Query Diff: customer_segments

image

value_segment has changed for some of those customers with a decreased CLV. This is expected and I'll notify the business team.


Top-k diff: value_segment

image

We've seen a 17% drop in high-value customers. We need to discuss with stakeholders whether an adjustment to the threshold is necessary.

There is no change in customer_order_pattern.

Value diff: customer_order_pattern

image

There is no change.

Changes to existing models:

N/A

Checklist:

This checklist is mostly useful as a reminder of small things that can easily be
forgotten – it is meant as a helpful tool rather than hoops to jump through.
Put an x in all the items that apply, make notes next to any that haven't been
addressed, and remove any items that are not relevant to this PR.

  • My pull request represents one logical piece of work.
  • My commits are related to the pull request and look clean.
  • My SQL follows the style guide.
  • I have materialized my models appropriately.
  • I have added appropriate tests and documentation to any new models.
  • I have updated the README file.

@even-wei even-wei changed the title Correct customer lifetime value calculation in customers Fix: customer lifetime value calculation in customers Jan 16, 2024
@clkao
Copy link

clkao commented Jan 16, 2024

Should we also check customer_order_pattern?

@clkao clkao changed the title Fix: customer lifetime value calculation in customers (Demo) Fix: customer lifetime value calculation in customers Jan 16, 2024
@even-wei
Copy link
Collaborator Author

There is no change in customer_order_pattern.
I will add it and update the checklist.
image

@even-wei
Copy link
Collaborator Author

Since the sources have been updated in the production environment, I've rebased the PR, rerun the checks, and updated the body. Most of the checks yield the same results, but I noticed that 99% of the value segments are classified as 'high value' (refer to the Top-k diff above). I plan to review the threshold next week.

@wcchang1115 wcchang1115 force-pushed the fix/customer-lifetime-value branch 2 times, most recently from eedae39 to 94036fd Compare April 9, 2024 08:20
@even-wei even-wei force-pushed the fix/customer-lifetime-value branch from 94036fd to 183171a Compare April 22, 2024 03:46
@DataRecce DataRecce deleted a comment from github-actions bot May 14, 2024
@DataRecce DataRecce deleted a comment from github-actions bot May 14, 2024
@DataRecce DataRecce deleted a comment from github-actions bot May 14, 2024
@DataRecce DataRecce deleted a comment from github-actions bot May 14, 2024
@DataRecce DataRecce deleted a comment from github-actions bot May 14, 2024
@DataRecce DataRecce deleted a comment from github-actions bot May 14, 2024

This comment was marked as outdated.

@popcornylu popcornylu force-pushed the fix/customer-lifetime-value branch from 231f592 to 4080960 Compare May 28, 2024 06:34

This comment was marked as outdated.

@popcornylu popcornylu force-pushed the fix/customer-lifetime-value branch from 4080960 to 01a9ef1 Compare May 30, 2024 09:47

This comment was marked as outdated.

@popcornylu popcornylu force-pushed the fix/customer-lifetime-value branch from 01a9ef1 to 2ff3a39 Compare June 5, 2024 08:19
Copy link

github-actions bot commented Jun 5, 2024

Recce Summary

Manifest Information

Manifest Catalog
Base 2024-11-05 07:49:11 2024-11-05 07:49:12
Current 2024-11-05 07:49:53 2024-11-05 07:49:54

Lineage Graph

graph LR
model.jaffle_shop.customers["customers

[What's Changed]
Code, Value Diff"]
style model.jaffle_shop.customers stroke:#ffa502
model.jaffle_shop.customers---->model.jaffle_shop.customer_segments
model.jaffle_shop.customers---->model.jaffle_shop.customer_order_pattern
model.jaffle_shop.customer_segments["customer_segments"]
model.jaffle_shop.customer_order_pattern["customer_order_pattern"]

Loading

Checks Summary

Checks Run Data Mismatch Detected
4 2

Checks of Data Mismatch Detected

Name Type Mismatched Nodes
Value diff of customers Value Diff customers
Query diff of customers avg lifetime value Query Diff N/A

See PR page: https://cloud.datarecce.io/DataRecce/jaffle_shop_duckdb/pulls/1

How to check the recce result

# Launch the recce server based on the state file
recce server --review --cloud --password yummy_jaffle

# Open the recce server http://localhost:8000 by your browser

@kentwelcome kentwelcome force-pushed the fix/customer-lifetime-value branch 2 times, most recently from 0c99b5a to 7ca327e Compare June 6, 2024 18:30
@wcchang1115 wcchang1115 force-pushed the fix/customer-lifetime-value branch 2 times, most recently from e9fbba7 to 383a007 Compare June 20, 2024 03:43
@wcchang1115 wcchang1115 force-pushed the fix/customer-lifetime-value branch 2 times, most recently from 75a349b to d5fe9c4 Compare August 13, 2024 07:40
@even-wei even-wei force-pushed the fix/customer-lifetime-value branch 2 times, most recently from 083a55b to 8337818 Compare October 29, 2024 05:05
@kentwelcome kentwelcome force-pushed the fix/customer-lifetime-value branch 5 times, most recently from 2c00e38 to 58feedb Compare November 5, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants