-
Notifications
You must be signed in to change notification settings - Fork 4
/
12_user_order_facts.view.lkml
99 lines (83 loc) · 2.33 KB
/
12_user_order_facts.view.lkml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
include: "thelook.model.lkml"
view: user_order_facts {
derived_table: {
explore_source: order_items {
column: user_id {}
column: lifetime_orders {field: order_items.order_count}
column: lifetime_revenue {field: order_items.total_sale_price}
column: first_order {}
column: latest_order {}
column: number_of_distinct_months_with_orders {field: order_items.month_count}
}
persist_for: "24 hours" ## Best practice would be to use `datagroup_trigger: ecommerce_etl` but we don't here for snowflake costs
}
dimension: user_id {
primary_key: yes
hidden: yes
sql: ${TABLE}.user_id ;;
}
##### Time and Cohort Fields ######
dimension_group: first_order {
type: time
timeframes: [date, week, month, year, raw]
sql: ${TABLE}.first_order ;;
}
dimension_group: latest_order {
type: time
timeframes: [date, week, month, year, raw]
sql: ${TABLE}.latest_order ;;
}
dimension: days_as_customer {
description: "Days between first and latest order"
type: number
sql: DATEDIFF('day', ${first_order_raw}, ${latest_order_raw})+1 ;;
}
dimension: days_as_customer_tiered {
type: tier
tiers: [0, 1, 7, 14, 21, 28, 30, 60, 90, 120]
sql: ${days_as_customer} ;;
style: integer
}
##### Lifetime Behavior - Order Counts ######
dimension: lifetime_orders {
type: number
sql: ${TABLE}.lifetime_orders ;;
}
dimension: repeat_customer {
description: "Lifetime Count of Orders > 1"
type: yesno
sql: ${lifetime_orders} > 1 ;;
}
dimension: lifetime_orders_tier {
type: tier
tiers: [0, 1, 2, 3, 5, 10]
sql: ${lifetime_orders} ;;
style: integer
}
measure: average_lifetime_orders {
type: average
value_format_name: decimal_2
sql: ${lifetime_orders} ;;
}
dimension: distinct_months_with_orders {
type: number
sql: ${TABLE}.number_of_distinct_months_with_orders ;;
}
##### Lifetime Behavior - Revenue ######
dimension: lifetime_revenue {
type: number
value_format_name: usd
sql: ${TABLE}.lifetime_revenue ;;
}
dimension: lifetime_revenue_tier {
type: tier
tiers: [0, 25, 50, 100, 200, 500, 1000]
sql: ${lifetime_revenue} ;;
style: integer
}
measure: average_lifetime_revenue {
type: average
value_format_name: usd
sql: ${lifetime_revenue} ;;
}
}