forked from quiccklabs/Labs_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Answering Complex Questions Using Native Derived Tables with LookML
177 lines (129 loc) · 3.76 KB
/
Answering Complex Questions Using Native Derived Tables with LookML
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
FILE NAME :- brand_order_facts
# If necessary, uncomment the line below to include explore_source.
# include: "training_ecommerce.model.lkml"
view: brand_order_facts {
derived_table: {
explore_source: order_items {
column: product_brand { field: inventory_items.product_brand }
column: total_revenue {}
derived_column: brand_rank {
sql: row_number() over (order by total_revenue desc) ;;
}
filters: [order_items.created_date: "365 days"]
bind_filters: {
from_field: order_items.created_date
to_field: order_items.created_date
}
}
}
dimension: brand_rank {
hidden: yes
type: number
}
dimension: product_brand {
description: ""
}
dimension: brand_rank_concat {
label: "Brand Name"
type: string
sql: ${brand_rank} || ') ' || ${product_brand} ;;
}
dimension: brand_rank_top_5 {
hidden: yes
type: yesno
sql: ${brand_rank} <= 5 ;;
}
dimension: brand_rank_grouped {
label: "Brand Name Grouped"
type: string
sql: case when ${brand_rank_top_5} then ${brand_rank_concat} else '6) Other' end ;;
}
dimension: total_revenue {
description: ""
value_format: "$#,##0.00"
type: number
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FILE NAME :- training_ecommerce
connection: "bigquery_public_data_looker"
# include all the views
include: "/views/*.view"
include: "/z_tests/*.lkml"
include: "/**/*.dashboard"
datagroup: training_ecommerce_default_datagroup {
# sql_trigger: SELECT MAX(id) FROM etl_log;;
max_cache_age: "1 hour"
}
persist_with: training_ecommerce_default_datagroup
label: "E-Commerce Training"
explore: order_items {
join: users {
type: left_outer
sql_on: ${order_items.user_id} = ${users.id} ;;
relationship: many_to_one
}
join: brand_order_facts {
type: left_outer
sql_on: ${inventory_items.product_brand} = ${brand_order_facts.product_brand} ;;
relationship: many_to_one
}
join: inventory_items {
type: left_outer
sql_on: ${order_items.inventory_item_id} = ${inventory_items.id} ;;
relationship: many_to_one
}
join: products {
type: left_outer
sql_on: ${inventory_items.product_id} = ${products.id} ;;
relationship: many_to_one
}
join: distribution_centers {
type: left_outer
sql_on: ${products.distribution_center_id} = ${distribution_centers.id} ;;
relationship: many_to_one
}
}
explore: events {
join: event_session_facts {
type: left_outer
sql_on: ${events.session_id} = ${event_session_facts.session_id} ;;
relationship: many_to_one
}
join: event_session_funnel {
type: left_outer
sql_on: ${events.session_id} = ${event_session_funnel.session_id} ;;
relationship: many_to_one
}
join: users {
type: left_outer
sql_on: ${events.user_id} = ${users.id} ;;
relationship: many_to_one
}
}
# Place in `training_ecommerce` model
explore: +order_items {
query: quicklabtask1 {
dimensions: [brand_order_facts.brand_rank_grouped]
measures: [total_revenue]
}
}
# Place in `training_ecommerce` model
explore: +order_items {
query: quicklabtask2 {
dimensions: [inventory_items.product_brand]
measures: [total_revenue]
}
}
# Place in `training_ecommerce` model
explore: +order_items {
query: quicklabtask3 {
dimensions: [brand_order_facts.brand_rank_grouped, created_date, users.age, users.country]
measures: [total_revenue]
filters: [
order_items.created_date: "365 days",
users.age: ">21",
users.country: "USA"
]
}
}