From d9496636f840d8d93f61daf73d971546168ca7e8 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 23 Feb 2026 14:29:10 +0000 Subject: [PATCH] dataportal: Modify int_customer_segments: add loyalty_score and churn risk columns --- dbt/models/intermediate/int_customer_segments.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dbt/models/intermediate/int_customer_segments.sql b/dbt/models/intermediate/int_customer_segments.sql index 3796ea6..a0be882 100644 --- a/dbt/models/intermediate/int_customer_segments.sql +++ b/dbt/models/intermediate/int_customer_segments.sql @@ -1,4 +1,5 @@ -- Segments customers by behavior +-- MODIFIED: Added loyalty_score and days_since_last_order columns with history as ( select * from {{ ref('int_customer_order_history') }} ), @@ -24,7 +25,11 @@ final as ( when returned_orders > 0 then true else false end as has_returns, - returned_orders * 1.0 / nullif(lifetime_orders, 0) as return_rate + returned_orders * 1.0 / nullif(lifetime_orders, 0) as return_rate, + -- NEW: Loyalty score based on orders and spend + (lifetime_orders * 10) + (lifetime_spend * 0.5) as loyalty_score, + -- NEW: Days since last order for churn risk + datediff('day', last_order_date, current_date) as days_since_last_order from history )