Skip to content

Commit 9bf0cc0

Browse files
author
Keith Fajardo
committed
commit changes
1 parent 961a243 commit 9bf0cc0

File tree

6 files changed

+161
-15
lines changed

6 files changed

+161
-15
lines changed

models/metrics/customers_metrics.yml

Whitespace-only changes.

models/metrics/dim_customers.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
semantic_models:
2+
3+
- name: customers
4+
defaults:
5+
agg_time_dimension: most_recent_order_date
6+
description: |
7+
semantic model for dim_customers
8+
9+
model: ref('dim_customers')
10+
11+
entities:
12+
- name: customer
13+
expr: customer_id
14+
type: primary
15+
16+
dimensions:
17+
- name: customer_name
18+
type: categorical
19+
expr: first_name
20+
21+
- name: first_order_date
22+
type: time
23+
type_params:
24+
time_granularity: day
25+
26+
- name: most_recent_order_date
27+
type: time
28+
type_params:
29+
time_granularity: day
30+
31+
measures:
32+
- name: count_lifetime_orders
33+
description: Total count of orders per customer.
34+
agg: sum
35+
expr: number_of_orders
36+
37+
- name: lifetime_spend
38+
agg: sum
39+
expr: lifetime_value
40+
description: Gross customer lifetime spend inclusive of taxes.
41+
42+
- name: customers
43+
expr: customer_id
44+
agg: count_distinct
45+
46+
metrics:
47+
- name: "customers_with_orders"
48+
label: "customers_with_orders"
49+
description: "Unique count of customers placing orders"
50+
type: simple
51+
type_params:
52+
measure:
53+
name: customers

models/metrics/fact_orders.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
semantic_models:
2+
3+
- name: orders
4+
defaults:
5+
agg_time_dimension: order_date
6+
description: |
7+
Order fact table. This table's grain is one row per order.
8+
model: ref('fact_orders')
9+
10+
entities:
11+
- name: order_id
12+
type: primary
13+
14+
- name: customer
15+
expr: customer_id
16+
type: foreign
17+
18+
dimensions:
19+
- name: order_date
20+
type: time
21+
type_params:
22+
time_granularity: day
23+
24+
measures:
25+
- name: order_total
26+
description: The total amount for each order including taxes.
27+
agg: sum
28+
expr: amount
29+
30+
- name: order_count
31+
expr: 1
32+
agg: sum
33+
34+
- name: customers_with_orders
35+
description: Distinct count of customers placing orders
36+
agg: count_distinct
37+
expr: customer_id
38+
39+
- name: order_value_p99 ## The 99th percentile order value
40+
expr: amount
41+
agg: percentile
42+
agg_params:
43+
percentile: 0.99
44+
use_discrete_percentile: True
45+
use_approximate_percentile: False

models/metrics/orders_metrics.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
metrics:
2+
# Simple type metrics
3+
- name: "order_total"
4+
description: "Sum of orders value"
5+
type: simple
6+
label: "order_total"
7+
type_params:
8+
measure:
9+
name: order_total
10+
11+
- name: "order_count"
12+
description: "number of orders"
13+
type: simple
14+
label: "order_count"
15+
type_params:
16+
measure:
17+
name: order_count
18+
19+
- name: large_orders
20+
description: "Count of orders with order total over 20."
21+
type: simple
22+
label: "Large Orders"
23+
type_params:
24+
measure:
25+
name: order_count
26+
filter: |
27+
{{ Metric('order_total', group_by=['order_id']) }} >= 20
28+
29+
# Ratio type metric
30+
- name: "avg_order_value"
31+
label: "avg_order_value"
32+
description: "average value of each order"
33+
type: ratio
34+
type_params:
35+
numerator: order_total
36+
denominator: order_count
37+
38+
# Cumulative type metrics
39+
- name: "cumulative_order_amount_mtd"
40+
label: "cumulative_order_amount_mtd"
41+
description: "The month to date value of all orders"
42+
type: cumulative
43+
type_params:
44+
measure:
45+
name: order_total
46+
grain_to_date: month
47+
# Derived metric
48+
- name: "pct_of_orders_that_are_large"
49+
label: "pct_of_orders_that_are_large"
50+
description: "percent of orders that are large"
51+
type: derived
52+
type_params:
53+
expr: large_orders/order_count
54+
metrics:
55+
- name: large_orders
56+
- name: order_count

models/sem_orders.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

models/semantic_layer_demo/marts/dim_customer.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
{{
2+
config(
3+
materialized='table',
4+
tags=["semantic_layer_demo"]
5+
)
6+
}}
7+
18
with customers as (
29
select * from {{ ref('stg_jaffle_shop__customers')}}
310
),

0 commit comments

Comments
 (0)