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

Add saved queries and exports for SL #21

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
40 changes: 40 additions & 0 deletions models/marts/customers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ semantic_models:
type_params:
time_granularity: day
measures:
- name: customers
description: Count of unique customers
agg: count_distinct
- name: count_lifetime_orders
description: Total count of orders per customer.
agg: sum
Expand All @@ -64,3 +67,40 @@ semantic_models:
- name: lifetime_spend
agg: sum
description: Gross customer lifetime spend inclusive of taxes.

metrics:
- name: lifetime_spend_pretax
description: Customer's lifetime spend before tax
label: LTV Pre-tax
type: simple
type_params:
measure: lifetime_spend_pretax
- name: count_lifetime_orders
description: Count of lifetime orders
label: Count Lifetime Orders
type: simple
type_params:
measure: count_lifetime_orders
- name: average_order_value
description: LTV pre-tax / number of orders
label: Average Order Value
type: derived
type_params:
metrics:
- count_lifetime_orders
- lifetime_spend_pretax
expr: lifetime_spend_pretax / count_lifetime_orders

saved_queries:
- name: customer_order_metrics
query_params:
metrics:
- count_lifetime_orders
- lifetime_spend_pretax
- average_order_value
group_by:
- Entity('customer')
exports:
- name: customer_order_metrics
config:
export_as: table
31 changes: 29 additions & 2 deletions models/marts/order_items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,30 @@ metrics:
type: simple
type_params:
measure: food_revenue
- name: drink_revenue
description: The revenue from drinks in each order
label: Drink Revenue
type: simple
type_params:
measure: drink_revenue

#Ratio Metrics
# Ratio Metrics
- name: food_revenue_pct
description: The % of order revenue from food.
label: Food Revenue %
type: ratio
type_params:
numerator: food_revenue
denominator: revenue
- name: drink_revenue_pct
description: The % of order revenue from drinks.
label: Drink Revenue %
type: ratio
type_params:
numerator: drink_revenue
denominator: revenue

#Derived Metrics
# Derived Metrics
- name: revenue_growth_mom
description: "Percentage growth of revenue compared to 1 month ago. Excluded tax"
type: derived
Expand Down Expand Up @@ -152,3 +165,17 @@ metrics:
type: cumulative
type_params:
measure: revenue

saved_queries:
- name: revenue_metrics
query_params:
metrics:
- revenue
- food_revenue
- drink_revenue
group_by:
- TimeDimension('metric_time', 'day')
exports:
- name: revenue_metrics
config:
export_as: table
16 changes: 14 additions & 2 deletions models/marts/orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ order_items_summary as (

),


compute_booleans as (

select
Expand All @@ -49,6 +48,19 @@ compute_booleans as (
order_items_summary
on orders.order_id = order_items_summary.order_id

),

add_customer_order_count as (

select
*,
row_number() over (
partition by customer_id
order by ordered_at asc
) as customer_order_number

from compute_booleans

)

select * from compute_booleans
select * from add_customer_order_count
26 changes: 26 additions & 0 deletions models/marts/orders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ semantic_models:
type: categorical
- name: is_drink_order
type: categorical
- name: customer_order_number
type: categorical
measures:
- name: order_total
description: The total amount for each order including taxes.
Expand All @@ -125,6 +127,14 @@ metrics:
label: Order Total
type_params:
measure: order_total
- name: new_customer_orders
description: New customer's first order count
label: New Customers
type: simple
type_params:
measure: order_count
filter: |
{{ Dimension('order_id__customer_order_number') }} = 1
- name: large_orders
description: "Count of orders with order total over 20."
type: simple
Expand Down Expand Up @@ -155,3 +165,19 @@ metrics:
measure: order_count
filter: |
{{ Dimension('order_id__is_drink_order') }} = true

saved_queries:
- name: order_metrics
query_params:
metrics:
- orders
- new_customer_orders
- order_total
- food_orders
- drink_orders
group_by:
- TimeDimension('metric_time', 'day')
exports:
- name: order_metrics
config:
export_as: table