-
Notifications
You must be signed in to change notification settings - Fork 35
/
bigquery.forex_historical_real.view.lkml
351 lines (320 loc) · 9.81 KB
/
bigquery.forex_historical_real.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
view: bq_forex_historical_real {
derived_table: {
sql: select x.day
, (case when x.AUD_USD is null then
(case when lag(x.AUD_USD, 1) over (order by x.day) is null then
lag(x.AUD_USD, 2) over (order by x.day)
Else lag(x.AUD_USD, 1) over (order by x.day) End)
Else x.AUD_USD End) as AUD_USD
, (case when x.CHF_JPY is null then
(case when lag(x.CHF_JPY, 1) over (order by x.day) is null then
lag(x.CHF_JPY, 2) over (order by x.day)
Else lag(x.CHF_JPY, 1) over (order by x.day) End)
Else x.CHF_JPY End) as CHF_JPY
, (case when x.EUR_CHF is null then
(case when lag(x.EUR_CHF, 1) over (order by x.day) is null then
lag(x.EUR_CHF, 2) over (order by x.day)
Else lag(x.EUR_CHF, 1) over (order by x.day) End)
Else x.EUR_CHF End) as EUR_CHF
, (case when x.EUR_GBP is null then
(case when lag(x.EUR_GBP, 1) over (order by x.day) is null then
lag(x.EUR_GBP, 2) over (order by x.day)
Else lag(x.EUR_GBP, 1) over (order by x.day) End)
Else x.EUR_GBP End) as EUR_GBP
, (case when x.EUR_JPY is null then
(case when lag(x.EUR_JPY, 1) over (order by x.day) is null then
lag(x.EUR_JPY, 2) over (order by x.day)
Else lag(x.EUR_JPY, 1) over (order by x.day) End)
Else x.EUR_JPY End) as EUR_JPY
, (case when x.EUR_USD is null then
(case when lag(x.EUR_USD, 1) over (order by x.day) is null then
lag(x.EUR_USD, 2) over (order by x.day)
Else lag(x.EUR_USD, 1) over (order by x.day) End)
Else x.EUR_USD End) as EUR_USD
, (case when x.GBP_CHF is null then
(case when lag(x.GBP_CHF, 1) over (order by x.day) is null then
lag(x.GBP_CHF, 2) over (order by x.day)
Else lag(x.GBP_CHF, 1) over (order by x.day) End)
Else x.GBP_CHF End) as GBP_CHF
, (case when x.GBP_JPY is null then
(case when lag(x.GBP_JPY, 1) over (order by x.day) is null then
lag(x.GBP_JPY, 2) over (order by x.day)
Else lag(x.GBP_JPY, 1) over (order by x.day) End)
Else x.GBP_JPY End) as GBP_JPY
, (case when x.GBP_USD is null then
(case when lag(x.GBP_USD, 1) over (order by x.day) is null then
lag(x.GBP_USD, 2) over (order by x.day)
Else lag(x.GBP_USD, 1) over (order by x.day) End)
Else x.GBP_USD End) as GBP_USD
, (case when x.NZD_USD is null then
(case when lag(x.NZD_USD, 1) over (order by x.day) is null then
lag(x.NZD_USD, 2) over (order by x.day)
Else lag(x.NZD_USD, 1) over (order by x.day) End)
Else x.NZD_USD End) as NZD_USD
, (case when x.USD_CAD is null then
(case when lag(x.USD_CAD, 1) over (order by x.day) is null then
lag(x.USD_CAD, 2) over (order by x.day)
Else lag(x.USD_CAD, 1) over (order by x.day) End)
Else x.USD_CAD End) as USD_CAD
, (case when x.USD_CHF is null then
(case when lag(x.USD_CHF, 1) over (order by x.day) is null then
lag(x.USD_CHF, 2) over (order by x.day)
Else lag(x.USD_CHF, 1) over (order by x.day) End)
Else x.USD_CHF End) as USD_CHF
, (case when x.USD_JPY is null then
(case when lag(x.USD_JPY, 1) over (order by x.day) is null then
lag(x.USD_JPY, 2) over (order by x.day)
Else lag(x.USD_JPY, 1) over (order by x.day) End)
Else x.USD_JPY End) as USD_JPY
from
(WITH
splitted AS (SELECT *
FROM
UNNEST( SPLIT(RPAD('',
1 + DATE_DIFF(CURRENT_DATE(), DATE("1999-01-01"), DAY),
'.'),''))),
with_row_numbers AS (
SELECT
ROW_NUMBER() OVER() AS pos, *
FROM splitted), calendar_day AS (
SELECT
cast(DATE_ADD(DATE("1999-01-01"), INTERVAL (pos - 1) DAY) as timestamp)AS day
FROM with_row_numbers)
SELECT *
FROM calendar_day
left join (
SELECT
cast(forex.exchange_date as timestamp) AS forex_exchange_date,
forex.AUD_USD AS AUD_USD,
forex.CHF_JPY AS CHF_JPY,
forex.EUR_CHF AS EUR_CHF,
forex.EUR_GBP AS EUR_GBP,
forex.EUR_JPY AS EUR_JPY,
forex.EUR_USD AS EUR_USD,
forex.GBP_CHF AS GBP_CHF,
forex.GBP_JPY AS GBP_JPY,
forex.GBP_USD AS GBP_USD,
forex.NZD_USD AS NZD_USD,
forex.USD_CAD AS USD_CAD,
forex.USD_CHF AS USD_CHF,
forex.USD_JPY AS USD_JPY
FROM `looker-datablocks.exchangerate.forex` AS forex
Group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14
Union All
SELECT
cast(forex_real.exchange_date as timestamp) AS forex_exchange_date,
1/(forex_real.AUD*(1/forex_real.USD)) AS AUD_USD,
1/(forex_real.CHF*(1/forex_real.JPY)) AS CHF_JPY ,
forex_real.CHF AS EUR_CHF,
forex_real.GBP AS EUR_GBP,
forex_real.JPY AS EUR_JPY,
forex_real.USD AS EUR_USD,
forex_real.CHF*(1/forex_real.GBP) AS GBP_CHF,
forex_real.JPY*(1/forex_real.GBP) AS GBP_JPY,
forex_real.USD*(1/forex_real.GBP) AS GBP_USD,
1/(forex_real.NZD*(1/forex_real.USD)) AS NZD_USD,
forex_real.CAD *(1/forex_real.USD) AS USD_CAD,
forex_real.CHF *(1/forex_real.USD) AS USD_CHF,
forex_real.JPY *(1/forex_real.USD) AS USD_JPY
FROM `looker-datablocks.exchangerate.forex_real_full` AS forex_real
Group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14
) as forex
on forex.forex_exchange_date = calendar_day.day) as x
order by day desc
;;
datagroup_trigger: default
}
dimension_group: forex_exchange {
type: time
timeframes: [date, week, month, year]
sql: ${TABLE}.day ;;
}
dimension: aud_usd {
label: "AUD/USD"
description: "1 Australian Dollar = X US Dollars"
value_format_name: decimal_4
type: number
sql: ${TABLE}.AUD_USD ;;
hidden: yes
}
dimension: chf_jpy {
label: "CHF/JPY"
description: "1 Swiss Franc = X Japanese Yen"
value_format_name: decimal_4
type: number
sql: ${TABLE}.CHF_JPY ;;
hidden: yes
}
dimension: eur_chf {
label: "EUR/CHF"
description: "1 Euro = X Swiss Francs"
value_format_name: decimal_4
type: number
sql: ${TABLE}.EUR_CHF ;;
hidden: yes
}
dimension: eur_gbp {
label: "EUR/GBP"
description: "1 Euro = X Great British Pounds"
value_format_name: decimal_4
type: number
sql: ${TABLE}.EUR_GBP ;;
hidden: yes
}
dimension: eur_jpy {
label: "EUR/JPY"
description: "1 Euro = X Japanese Yen"
value_format_name: decimal_4
type: number
sql: ${TABLE}.EUR_JPY ;;
hidden: yes
}
dimension: eur_usd {
label: "EUR/USD"
description: "1 Euro = X US Dollars"
type: number
sql: ${TABLE}.EUR_USD ;;
hidden: yes
}
dimension: gbp_chf {
label: "GBP/CHF"
description: "1 Great British Pound = X Swiss Francs"
type: number
sql: ${TABLE}.GBP_CHF ;;
hidden: yes
}
dimension: gbp_jpy {
label: "GBP/JPY"
description: "1 Great British Pound = X Japanese Yen"
type: number
sql: ${TABLE}.GBP_JPY ;;
hidden: yes
}
dimension: gbp_usd {
label: "GBP/USD"
description: "1 Great British Pound = X US dollars"
type: number
sql: ${TABLE}.GBP_USD ;;
hidden: yes
}
dimension: nzd_usd {
label: "NZD/USD"
description: "1 New Zealand Dollar = X US dollars"
type: number
sql: ${TABLE}.NZD_USD ;;
hidden: yes
}
dimension: usd_cad {
label: "USD/CAD"
description: "1 US dollar = X Canadian dollars"
type: number
sql: ${TABLE}.USD_CAD ;;
hidden: yes
}
dimension: usd_chf {
label: "USD/CHF"
description: "1 US dollar = X Swiss Francs"
type: number
sql: ${TABLE}.USD_CHF ;;
hidden: yes
}
dimension: usd_jpy {
label: "USD/JPY"
description: "1 US dollar = X Japanese Yen"
type: number
sql: ${TABLE}.USD_JPY ;;
hidden: yes
}
################################### measures to plot on graph ###################################
measure: audusd {
label: "AUD/USD"
description: "1 Australian Dollar = X US Dollars"
value_format_name: decimal_4
type: max
sql: ${aud_usd} ;;
}
measure: chfjpy {
label: "CHF/JPY"
description: "1 Swiss Franc = X Japanese Yen"
value_format_name: decimal_4
type: max
sql: ${chf_jpy};;
}
measure: eurchf {
label: "EUR/CHF"
description: "1 Euro = X Swiss Francs"
value_format_name: decimal_4
type: max
sql: ${eur_chf} ;;
}
measure: eurgbp {
label: "EUR/GBP"
description: "1 Euro = X Great British Pounds"
value_format_name: decimal_4
type: max
sql: ${eur_gbp} ;;
}
measure: eurjpy {
label: "EUR/JPY"
description: "1 Euro = X Japanese Yen"
value_format_name: decimal_4
type: max
sql: ${eur_jpy};;
}
measure: eurusd {
label: "EUR/USD"
description: "1 Euro = X US Dollars"
value_format_name: decimal_4
type: max
sql: ${eur_usd} ;;
}
measure: gbpchf {
label: "GBP/CHF"
description: "1 Great British Pound = X Swiss Francs"
value_format_name: decimal_4
type: max
sql: ${gbp_chf};;
}
measure: gbpjpy {
label: "GBP/JPY"
description: "1 Great British Pound = X Japanese Yen"
value_format_name: decimal_4
type: max
sql: ${gbp_jpy} ;;
}
measure: gbpusd {
label: "GBP/USD"
description: "1 Great British Pound = X US dollars"
value_format_name: decimal_4
type: max
sql: ${gbp_usd} ;;
}
measure: nzdusd {
label: "NZD/USD"
description: "1 New Zealand Dollar = X US dollars"
value_format_name: decimal_4
type: max
sql: ${nzd_usd};;
}
measure: usdcad {
label: "USD/CAD"
description: "1 US dollar = X Canadian dollars"
value_format_name: decimal_4
type: max
sql: ${usd_cad} ;;
}
measure: usdchf {
label: "USD/CHF"
description: "1 US dollar = X Swiss Francs"
value_format_name: decimal_4
type: max
sql: ${usd_chf} ;;
}
measure: usdjpy {
label: "USD/JPY"
description: "1 US dollar = X Japanese Yen"
value_format_name: decimal_4
type: max
sql: ${usd_jpy} ;;
}
}