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 12, 2024
1 parent 1d0c996 commit 57c7e97
Show file tree
Hide file tree
Showing 5 changed files with 55 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"]
15 changes: 15 additions & 0 deletions jaffle_shop/models/final/finance/_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2

models:
- name: fnl_returned_order_value
meta:
owner: joshua.oconnor@kraken.tech
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
orders.customer_id AS customer_id,
orders.amount as total_amount
FROM {{ ref('wh_orders') }}
WHERE orders.status = 'returned'
)

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

models:
- name: fnl_monthly_customer_count
meta:
owner: joshua.oconnor@kraken.tech
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 57c7e97

Please sign in to comment.