From 74d96f37dc0a225bda764a43d2dc92e293135d37 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 22 Feb 2026 18:50:01 +0000 Subject: [PATCH] dataportal: accept SQL changes for core_excellent_cohort_revenue Co-authored-by: Cursor --- .../core/core_excellent_cohort_revenue.sql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 dbt/models/marts/core/core_excellent_cohort_revenue.sql diff --git a/dbt/models/marts/core/core_excellent_cohort_revenue.sql b/dbt/models/marts/core/core_excellent_cohort_revenue.sql new file mode 100644 index 0000000..2607b6d --- /dev/null +++ b/dbt/models/marts/core/core_excellent_cohort_revenue.sql @@ -0,0 +1,36 @@ +-- Total revenue summary for products in the Excellent rating cohort (avg_rating >= 4.5) +-- Filters dim_products to rating_tier = 'Excellent' and aggregates revenue, +-- profit, units sold, and margin metrics at the cohort level. +with source as ( + + select + product_id, + product_name, + product_category, + avg_rating, + rating_tier, + total_units_sold, + product_total_revenue, + product_gross_profit, + margin_pct + from {{ ref('dim_products') }} + where rating_tier = 'Excellent' + +), + +final as ( + + select + rating_tier, + count(product_id) as product_count, + sum(product_total_revenue) as total_revenue, + sum(product_gross_profit) as total_gross_profit, + sum(total_units_sold) as total_units_sold, + round(avg(avg_rating)::numeric, 2) as avg_rating, + round(avg(margin_pct)::numeric, 4) as avg_margin_pct + from source + group by rating_tier + +) + +select * from final