Skip to content

Commit

Permalink
Add final tables for two dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmalins committed Dec 8, 2022
1 parent 9978716 commit 92c98a9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
28 changes: 28 additions & 0 deletions jaffle_shop/models/final/finance/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2

exposures:
- name: customer_lifetime_returns_value_dashboard
label: 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: "[email protected]"
depends_on:
- ref('fnl_finance_customerlifetimereturns')

models:
- name: fnl_finance_customerlifetimereturns
meta:
owner: "[email protected]"
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
customer_id
, SUM(amount) as customer_lifetime_returns
FROM {{ ref('wh_orders') }}
WHERE status = 'returned'
GROUP BY customer_id
28 changes: 28 additions & 0 deletions jaffle_shop/models/final/sales/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2

exposures:
- name: new_customers_dashboard
label: Montlhly 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: "[email protected]"
depends_on:
- ref('fnl_sales_newcustomers')

models:
- name: fnl_sales_newcustomers
meta:
owner: "[email protected]"
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.
12 changes: 12 additions & 0 deletions jaffle_shop/models/final/sales/fnl_sales_newcustomers.sql
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 92c98a9

Please sign in to comment.