forked from dbt-labs/jaffle-shop-classic
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add finance and sales models for final layer
Add fnl_monthly_customer_count dashboard to sales models Add finance and sales models for final layer
- Loading branch information
1 parent
728f10b
commit f1358e5
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest_plugins = ["dbt.tests.fixtures.project"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
jaffle_shop/models/final/finance/fnl_returned_order_value.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
jaffle_shop/models/final/sales/fnl_monthly_customer_count.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |