Skip to content

Commit

Permalink
Add finance and sales models for final layer
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadias2212 committed Apr 16, 2024
1 parent 728f10b commit 2036dac
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest_plugins = ["dbt.tests.fixtures.project"]
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: fnl_returned_order_value
label: Inkacio
description: fnl_returned_order_value
type: dashboard
url: https://inksacio.eks.octopus.engineering/my_certification_dashboard/
owner:
email: [email protected]
depends_on:
- ref('wh_orders')


models:
- name: fnl_returned_order_value
meta:
owner: [email protected]
description: |
One row per customer for total value of returns
columns:
- name: customer_id
description: Primary key
tests:
- unique
- not_null

13 changes: 13 additions & 0 deletions jaffle_shop/models/final/finance/fnl_returned_order_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
WITH returned_orders AS (
SELECT
customer_id AS customer_id
,amount as total_amount
FROM {{ ref('wh_orders') }}
WHERE status = 'returned'
)

SELECT
customer_id
,SUM(COALESCE(total_amount, 0)) AS total_value
FROM returned_orders
GROUP BY customer_id
26 changes: 26 additions & 0 deletions jaffle_shop/models/final/sales/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2


exposures:
- name: fnl_monthly_customer_count
label: Inkacio
description: fnl_monthly_customer_count
type: dashboard
url: https://inksacio.eks.octopus.engineering/my_certification_dashboard/
owner:
email: [email protected]
depends_on:
- ref('wh_customers')

models:
- name: fnl_monthly_customer_count
meta:
owner: [email protected]
description: |
One row per customer count for each month based on their first orders.
columns:
- name: first_order_month
description: Primary key
tests:
- unique
- not_null
12 changes: 12 additions & 0 deletions jaffle_shop/models/final/sales/fnl_monthly_customer_count.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WITH customer_orders AS (
SELECT
customer_id
, DATE_FORMAT(first_order, 'MMMM') As order_month
FROM {{ ref('wh_customers') }}
)

SELECT
first_order AS first_order_month
, COUNT(*) AS customer_count
FROM customer_orders
GROUP BY first_order

0 comments on commit 2036dac

Please sign in to comment.