Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: add order metrics #33

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions models/metricflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
semantic_models:
- name: orders
defaults:
agg_time_dimension: order_date
description: >
This is different to the underlying models?
model: ref('orders')
entities:
- name: order_id
type: primary
- name: customer_id
type: foreign
dimensions:
- name: is_completed
type: categorical
- name: order_date
type: time
type_params:
time_granularity: day
- name: status
type: categorical
measures:
- name: order_count
agg: count_distinct
expr: order_id
- name: first_order
agg: min
expr: order_date
- name: last_order
agg: max
expr: order_date
- name: average_order_size
agg: average
expr: amount
- name: total_order_amount
agg: sum
expr: amount

metrics:
- name: order_count
type: simple
type_params:
measure: order_count
label: Order count
- name: completed_order_count
label: Completed order count
type: simple
type_params:
measure: order_count
filter: |
{{ Dimension('order_id__is_completed') == true }}
- name: fulfilment_rate
label: Fulfilment rate
type: derived
type_params:
expr: SAFE_DIVIDE(completed_order_count, order_count)
24 changes: 24 additions & 0 deletions models/metricflow_time_spine.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{
config(
materialized = 'table',
)
}}

with days as (

{{
dbt_utils.date_spine(
'day',
"to_date('01/01/2000','mm/dd/yyyy')",
"to_date('01/01/2027','mm/dd/yyyy')"
)
}}

),

final as (
select cast(date_day as date) as date_day
from days
)

select * from final
34 changes: 0 additions & 34 deletions models/schema.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
version: 2
metrics:
- name: unique_customer_count
label: Unique customer count
model: ref('customers')
description: Total number of customers
type: count_distinct
sql: customer_id
timestamp: created
time_grains: [day, week, month, quarter, year]
- name: completed_order_count
label: Completed order count
model: ref('orders')
description: Total number of completed orders
type: count_distinct
sql: order_id
timestamp: order_date
time_grains: [day, week, month, quarter, year]
filters:
- field: is_completed
operator: '='
value: 'true'
- name: dbt_expression
label: dbt_expression
description: derived metric in v1.2 ( deprecated )
type: expression
sql: "{{metric('unique_customer_count')}} / {{metric('unique_customer_count')}}"
timestamp: created
time_grains: [ day, week, month, quarter, year ]
- name: dbt_derived
label: dbt_derived
calculation_method: derived
expression: "{{metric('unique_customer_count')}} / {{metric('unique_customer_count')}}"
timestamp: created
time_grains: [ day, week, month, quarter, year ]
models:
- name: customers
description: >-
Expand Down