forked from annalooker/partner_homepage_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25_trailing_sales_snapshot.view.lkml
79 lines (64 loc) · 1.66 KB
/
25_trailing_sales_snapshot.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
view: trailing_sales_snapshot {
derived_table: {
# sql_trigger_value: select current_date ;;
sql: with calendar as
(select distinct to_date(created_at) as snapshot_date
from inventory_items
-- where dateadd('day',90,created_at)>=current_date
)
select
inventory_items.product_id
,to_date(order_items.created_at) as snapshot_date
,count(*) as trailing_28d_sales
from order_items
left join inventory_items on order_items.inventory_item_id = inventory_items.id
left join calendar
on order_items.created_at <= dateadd('day',28,calendar.snapshot_date)
and order_items.created_at >= calendar.snapshot_date
-- where dateadd('day',90,calendar.snapshot_date)>=current_date
group by 1,2
;;
}
# measure: count {
# type: count
# drill_fields: [detail*]
# }
dimension: product_id {
type: number
sql: ${TABLE}.product_id ;;
}
dimension: snapshot_date {
type: date
sql: ${TABLE}.snapshot_date ;;
}
dimension: trailing_28d_sales {
type: number
hidden: yes
sql: ${TABLE}.trailing_28d_sales ;;
}
measure: sum_trailing_28d_sales {
type: sum
sql: ${trailing_28d_sales} ;;
}
measure: sum_trailing_28d_sales_yesterday {
type: sum
hidden: yes
sql: ${trailing_28d_sales} ;;
filters: {
field: snapshot_date
value: "yesterday"
}
}
measure: sum_trailing_28d_sales_last_wk {
type: sum
hidden: yes
sql: ${trailing_28d_sales} ;;
filters: {
field: snapshot_date
value: "8 days ago for 1 day"
}
}
set: detail {
fields: [product_id, snapshot_date, trailing_28d_sales]
}
}