Skip to content

Test2/feature/financial metrics clv revenue#4

Open
iamcxa wants to merge 10 commits intomainfrom
test2/feature/financial-metrics-clv-revenue
Open

Test2/feature/financial metrics clv revenue#4
iamcxa wants to merge 10 commits intomainfrom
test2/feature/financial-metrics-clv-revenue

Conversation

@iamcxa
Copy link

@iamcxa iamcxa commented Oct 30, 2025

No description provided.

@DataRecce DataRecce deleted a comment from claude bot Oct 30, 2025
@DataRecce DataRecce deleted a comment from claude bot Oct 30, 2025
@DataRecce DataRecce deleted a comment from claude bot Oct 30, 2025
@DataRecce DataRecce deleted a comment from claude bot Oct 30, 2025
@DataRecce DataRecce deleted a comment from recce-cloud bot Oct 30, 2025
@DataRecce DataRecce deleted a comment from claude bot Oct 30, 2025
@iamcxa
Copy link
Author

iamcxa commented Oct 30, 2025

@claude

@claude
Copy link

claude bot commented Oct 30, 2025

Claude finished @iamcxa's task —— View job


PR Validation Summary

⚠ Anomalies Detected

🔴 Schema Changes Detected - New columns added to core models:

  • customers model: Added 1 new column (net_customer_lifetime_value)
  • customer_segments model: Added 2 new columns (net_customer_lifetime_value, net_value_segment)
  • stg_payments model: Added 1 new column (coupon_amount)

Business Logic Changes - CLV calculation methodology modified:

  • Changed from single CLV metric to dual CLV tracking (gross vs. net)
  • Added filtering for completed orders only (orders.status = 'completed')
  • Added data quality filters (non-null, positive amounts only)
  • New coupon tracking in staging layer

Unable to Validate Data Quality - Runtime errors encountered:

  • Row count validation failed: finance_revenue table not built in current environment
  • Value diff validation failed: Models need to be rebuilt before comparison
  • Profile diff validation failed: No data available for comparison

Changes Overview

  • Models: 3 modified, 1 new, 0 removed
  • Schema Changes: 4 columns added across 3 models
  • New Model: finance_revenue (revenue tracking with gross/net metrics)

Modified Models & Columns

customers (modified)

  • ✅ Renamed: total_amountcustomer_lifetime_value (gross CLV)
  • ➕ Added: net_customer_lifetime_value (net CLV excluding coupons)
  • 🔧 Logic change: Now filters for completed orders only
  • 🔧 Logic change: Added data quality filters (non-null, positive amounts)

customer_segments (modified)

  • ➕ Added: net_customer_lifetime_value column
  • ➕ Added: net_value_segment column (segmentation based on net CLV)

stg_payments (modified)

  • ➕ Added: coupon_amount column (extracted from payment_method)

finance_revenue (new)

  • New revenue tracking model with gross/net revenue metrics per order
  • Columns: order_id, customer_id, order_date, status, gross_revenue, net_revenue

Downstream Impact

The changes to customers model impact:

  • customer_segments (direct dependency - updated to use new column)
  • customer_order_pattern (indirect dependency - may need review)

✅ Test Status

  • Schema validation: Successfully retrieved lineage diff showing 3 modified models + 1 new model
  • Row count validation: Failed - models not built in current environment
  • Value diff validation: Failed - customers table not available for comparison
  • Query diff validation: Failed - customers table not available for comparison

Note: The preset checks could not complete due to models not being built in the current (dev) environment. The data has been built in the base (prod) environment but not in the current branch's environment.


📊 Schema Changes Analysis

stg_payments Schema Change

Added column: coupon_amount

-- NEW: Line 20
(payment_method = 'coupon')::int * (amount / 100) as coupon_amount

This creates a new metric to track coupon amounts separately, enabling net revenue calculations.

customers Schema & Logic Changes

Column changes:

  • total_amount renamed to customer_lifetime_value (gross)
  • Added net_customer_lifetime_value (net of coupons)

Business logic changes:

-- BEFORE
sum(amount)::bigint as total_amount

-- AFTER
sum(amount)::bigint as gross_amount, -- Includes coupon amount
sum(amount - coupon_amount)::bigint as net_amount, -- Excludes coupon amount

New filtering logic:

-- Added: Only completed orders
and orders.status = 'completed'

-- Added: Data quality filters
where payments.amount is not null
  and payments.amount > 0

customer_segments Schema Changes

Added columns:

  • net_customer_lifetime_value (passes through from customers)
  • net_value_segment (new segmentation based on net CLV)

🔍 Suggested Checks

Critical validations needed before merge:

  1. Build & Test Current Environment: Run dbt build in the dev environment to ensure all models compile and execute successfully

  2. Row Count Validation: After building, verify row counts match expectations

    • Check: customers, orders, customer_segments, finance_revenue
  3. CLV Metric Validation: Verify the impact of business logic changes

    • Completed orders filter: Confirm expected reduction in CLV values due to filtering out non-completed orders
    • Data quality filters: Validate that null/negative amounts exclusion doesn't drop legitimate records
    • Coupon logic: Verify coupon_amount calculation is correct and net CLV = gross CLV - coupons
  4. Downstream Impact: Validate dependent models

    • Check: customer_order_pattern still works with new customers schema
    • Check: Any BI dashboards or reports using customer_lifetime_value need updates?
  5. Query Diff Validation (after build):

  6. Value Diff Validation (after build):

    • Run preset check [bad example] fac_orders #3: 100% match validation for customer_id and customer_lifetime_value
    • Expect differences due to business logic changes - verify they're intentional
  7. Finance Revenue Model: Validate the new finance_revenue model

    • Verify gross vs net revenue calculations are correct
    • Check for any unexpected NULL values in revenue columns

📝 Summary

This PR introduces a significant enhancement to financial metrics tracking by:

  1. Splitting CLV into gross and net metrics to account for coupon impacts
  2. Improving data quality with filters for completed orders and valid payment amounts
  3. Adding a new revenue model (finance_revenue) for centralized revenue tracking
  4. Extending customer segmentation with net value segments

⚠️ Important Notes:

  • The preset validation checks could not fully execute because models need to be built in the current environment
  • The business logic changes will impact CLV values (likely decrease due to completed-orders-only filter)
  • This is a breaking change for any downstream consumers expecting the old total_amount column name
  • Recommend thorough validation of CLV calculations before merging, especially the impact of the completed orders filter

Recommended Next Steps:

  1. Build models in dev environment: dbt build --select state:modified+
  2. Run full Recce validation suite after build
  3. Validate CLV changes are as expected
  4. Update any documentation or BI dashboards referencing the old column names

@datarecce-local-dev
Copy link

datarecce-local-dev bot commented Jan 7, 2026

Summary

PR #4 introduces financial metrics functionality, specifically adding revenue and customer lifetime value (CLV) models to the dbt project. The changes include 129 additions and 9 deletions across 7 files, with the primary focus on creating a new finance_revenue.sql model and updating related schemas and customer segments.

Key Changes

  • New Model Added: finance_revenue.sql (31 lines) - Introduces revenue calculation and financial metrics for customer analysis
  • Schema Updates: models/schema.yml enhanced with 72 additions and 5 deletions - Documenting new metrics, tests, and model relationships
  • Customer Segments Enhanced: Modified to support CLV calculations with 7 additions and 1 deletion
  • Customers Model Updated: Added 8 lines and removed 2 lines to support new financial dimensions
  • Staging Layer: stg_payments.sql refined with minor adjustments (2 additions, 1 deletion)
  • Configuration: Added entries to .gitignore to exclude target artifacts (1 addition)

Impact Analysis

File Change Summary:

  • 🟢 Revenue Model: New finance_revenue model created with complete revenue aggregation logic
  • 🟡 Schema Documentation: Significant expansion of dbt YAML documentation with metrics and test coverage
  • 🔵 Core Models Modified: Customer and segment models enhanced to support financial calculations
  • 📊 Data Lineage: Changes cascade through customer dimensions to enable CLV and revenue analysis

Affected Downstream Dependencies:

  • Customer segments now depend on enhanced revenue calculations
  • Potential impact on downstream BI tools consuming customer dimension tables
  • New metrics available for dashboard and reporting layer

🔍 Suggested Actions

  • Validate Revenue Calculations: Confirm finance_revenue.sql calculations match business financial definitions and period conventions
  • Review New Metrics: Ensure CLV and revenue metrics meet data governance and accuracy standards before production deployment
  • Test Downstream Impact: Verify that changes to customer and segment models don't break existing reports or dashboards
  • Documentation Review: Check that new schema.yml entries include clear descriptions, owners, and SLAs for stakeholders
  • Performance Analysis: Monitor query performance of the new finance_revenue model, especially with large customer datasets

Note: This summary is based on the PR metadata and file changes. For deeper data quality validation and lineage analysis, consider running dbt test suites and validating model row counts against expected values.


Was this summary helpful? 👍 👎

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.

3 participants