-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer_facts.view.lkml
85 lines (74 loc) · 2.49 KB
/
customer_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
view: customer_facts {
derived_table: {
sql_trigger_value: select DATE_TRUNC('month',current_date);;
indexes: ["email"]
sql: SELECT *
, lead(total_amount) over(PARTITION BY table_a.email ORDER by email, table_a.charge_month DESC) as previous_amount
, row_number() over() as id
FROM (
SELECT
ufds.email AS "email",
DATE_TRUNC('month', zinvoiceitems."ChargeDate" ) AS "charge_month",
COALESCE(SUM(("ChargeAmount") ), 0) AS "total_amount"
FROM smartdc.zinvoiceitems AS zinvoiceitems
LEFT JOIN smartdc.ufds AS ufds ON ("AccountNumber") = ufds.uuid
LEFT JOIN smartdc.zuora_customers AS zuora_customers ON zuora_customers.accountnumber = ("AccountNumber")
GROUP BY 1,DATE_TRUNC('month', zinvoiceitems."ChargeDate" )
) as table_a
;;
}
measure: count {
description: "Count of unique customers"
type: count
drill_fields: [detail*]
}
dimension: id {
description: "The row number from zinvoiceitems joined with ufds, and zuora_customers"
primary_key: yes
}
dimension: email {
description: "ufds.email"
type: string
sql: ${TABLE}.email ;;
}
dimension: charge_month {
description: "the month derived from the zinvoicesitems.ChargeDate"
type: date
sql: ${TABLE}.charge_month ;;
}
dimension: total_amount {
description: "zinvoiceitems.ChargeAmount or 0"
type: string
sql: ${TABLE}.total_amount ;;
}
dimension: previous_amount {
description: "total_amount from the previous row"
type: string
sql: ${TABLE}.previous_amount ;;
}
dimension: is_seemless_sale {
description: "boolean if previous_amount is 0 and total_amount is != 0 OR previous_amount is null and total_amount is not null"
type: yesno
sql: (${previous_amount} = 0 AND ${total_amount} != 0)
OR (${previous_amount} is null AND ${total_amount} is not null) ;;
}
dimension: change {
description: "change from prior month"
type: number
sql: ${total_amount}-${previous_amount};;
value_format_name: decimal_2
# sql: 1.0*(${total_amount}-${previous_amount})/nullif(${previous_amount},0) ;;
# value_format_name: percent_0
}
measure: avg_change {
description: "Average amount of change"
type: average
sql: ${change} ;;
value_format_name: decimal_2
drill_fields: [email,previous_amount,total_amount,change]
# value_format_name: percent_0
}
set: detail {
fields: [email, charge_month, total_amount, previous_amount]
}
}