Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 2602696

Browse files
Add finance and sales models for returned order value and monthly customer count
1 parent 8ef7391 commit 2602696

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
3+
models:
4+
- name: fnl_returned_order_value
5+
meta:
6+
owner: kensuke.morris@octoenergy.com
7+
description: |
8+
One row per total value of returned orders per customer
9+
columns:
10+
- name: customer_id
11+
description: Primary key
12+
tests:
13+
- unique
14+
- not_null
15+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
WITH returned_orders AS (
2+
SELECT *
3+
FROM {{ ref('wh_orders') }}
4+
WHERE status = 'returned'
5+
)
6+
7+
customers AS (
8+
SELECT *
9+
FROM {{ref('stg_customers') }}
10+
)
11+
12+
SELECT
13+
customer_id
14+
, SUM(COALESCE(total_amount, 0) AS total_value
15+
FROM returned_orders
16+
LEFT JOIN customers
17+
ON returned_orders.customer_id = customers.customer_id
18+
GROUP BY customer_id
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
3+
models:
4+
- name: fnl_monthly_customer_count
5+
meta:
6+
owner: kensuke.morris@octoenergy.com
7+
description: |
8+
One row per customer count for each month based on their first orders.
9+
columns:
10+
- name: first_order_month
11+
description: Primary key
12+
tests:
13+
- unique
14+
- not_null
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
WITH customer_orders AS (
2+
SELECT
3+
customer_id
4+
, DATE_FORMAT(first_order, 'MMMM') As order_month
5+
FROM {{ ref('wh_customers') }}
6+
)
7+
8+
SELECT
9+
first_order AS first_order_month
10+
, COUNT(*) AS customer_count
11+
FROM customer_orders
12+
GROUP BY first_order

0 commit comments

Comments
 (0)