diff --git a/jaffle_shop/models/final/finance/_models.yml b/jaffle_shop/models/final/finance/_models.yml new file mode 100644 index 000000000..b5e193981 --- /dev/null +++ b/jaffle_shop/models/final/finance/_models.yml @@ -0,0 +1,27 @@ +version: 2 + +exposures: + - name: Customer lifetime returns value dashboard + description: A dashboard for the lifetime value (total amount) of returns from each customer. + type: dashboard + url: https://prod-apnortheast-a.online.tableau.com/#/site/octopusenergyjapan/home/customerlifetimereturns + owner: + email: "alex.malins@octoenergy.com" + depends_on: + - ref('fnl_finance_customerlifetimereturns') + +models: + - name: fnl_finance_customerlifetimereturns + meta: + owner: "alex.malins@octoenergy.com" + team_owner: '!subteam^S02GPV1135F' #@dbt_gatekeepers + description: | + Table with the total sales for each customer. + columns: + - name: customer_id + description: Unique customer id. + tests: + - unique + - not_null + - name: customer_lifetime_returns + description: Total value of all orders returned by customer. diff --git a/jaffle_shop/models/final/finance/fnl_finance_customerlifetimereturns.sql b/jaffle_shop/models/final/finance/fnl_finance_customerlifetimereturns.sql new file mode 100644 index 000000000..1f424b6e9 --- /dev/null +++ b/jaffle_shop/models/final/finance/fnl_finance_customerlifetimereturns.sql @@ -0,0 +1,6 @@ +SELECT + customer_id + , SUM(amount) as customer_lifetime_returns +FROM {{ ref('wh_orders') }} +WHERE status = 'returned' +GROUP BY customer_id diff --git a/jaffle_shop/models/final/sales/_models.yml b/jaffle_shop/models/final/sales/_models.yml new file mode 100644 index 000000000..0b25630b0 --- /dev/null +++ b/jaffle_shop/models/final/sales/_models.yml @@ -0,0 +1,27 @@ +version: 2 + +exposures: + - name: New customers dashboard + description: A dashboard for the number of new customers making first orders each month. + type: dashboard + url: https://prod-apnortheast-a.online.tableau.com/#/site/octopusenergyjapan/home/monthlynewcustomers + owner: + email: "alex.malins@octoenergy.com" + depends_on: + - ref('fnl_sales_newcustomers') + +models: + - name: fnl_sales_newcustomers + meta: + owner: "alex.malins@octoenergy.com" + team_owner: '!subteam^S02GPV1135F' #@dbt_gatekeepers + description: | + Count of new customers (i.e. ones making their first order) each month. + columns: + - name: year_month + description: Year and month. + tests: + - unique + - not_null + - name: new_customers + description: Number of new customers making first orders that month. \ No newline at end of file diff --git a/jaffle_shop/models/final/sales/fnl_sales_newcustomers.sql b/jaffle_shop/models/final/sales/fnl_sales_newcustomers.sql new file mode 100644 index 000000000..0f24f6bb5 --- /dev/null +++ b/jaffle_shop/models/final/sales/fnl_sales_newcustomers.sql @@ -0,0 +1,12 @@ +WITH customer_first_orders AS ( + SELECT + DATE_TRUNC('MONTH', first_order) AS year_month + FROM {{ ref('wh_customers') }} + WHERE first_order IS NOT NULL +) + +SELECT + year_month + , COUNT(1) AS new_customers +FROM customer_first_orders +GROUP BY year_month