-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperiod_over_period.lkml
56 lines (51 loc) · 2.37 KB
/
period_over_period.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
parameter: previous_period_comparison_granularity {
description: "Select the comparison period. E.g. choosing Month will compare the selected range against the same dates 30 days ago. "
type: unquoted
allowed_value: {
label: "Week"
value: "7"
}
allowed_value: {
label: "Month"
value: "30"
}
allowed_value: {
label: "Year"
value: "365"
}
}
filter: previous_period_filter {
label: "Previous Period/This Period filter Range"
description: "Previous Period Filter for specific measures. User Date filter for any regular measures."
type: date
sql:
{% if period_over_period._in_query %}
(${created_date} >= {% date_start previous_period_filter %}
AND ${created_date} <= {% date_end previous_period_filter %})
OR
(${created_date} >= DATEADD(day,-{{ previous_period_comparison_granularity._parameter_value }}, {% date_start previous_period_filter %} )
AND ${created_date} <= DATEADD(day,-{{ previous_period_comparison_granularity._parameter_value }}+DATEDIFF(day,{% date_start previous_period_filter %}, {% date_end previous_period_filter %}),{% date_start previous_period_filter %} ))
{% else %}
{% condition previous_period_filter %} CAST(${created_raw} as DATE) {% endcondition %}
{% endif %}
;;
}
dimension: period_over_period {
type: string
description: "The reporting period as selected by the Previous Period Filter"
sql:
CASE
WHEN {% date_start previous_period_filter %} is not null AND {% date_end previous_period_filter %} is not null /* date ranges or in the past x days */
THEN
CASE
WHEN ${created_date} >= {% date_start previous_period_filter %}
AND ${created_date} <= {% date_end previous_period_filter %}
THEN 'This Period'
WHEN ${created_date} >= DATEADD(day,-{{ previous_period_comparison_granularity._parameter_value }}, {% date_start previous_period_filter %} )
AND ${created_date} <= DATEADD(day,-{{ previous_period_comparison_granularity._parameter_value }}+DATEDIFF(day,{% date_start previous_period_filter %}, {% date_end previous_period_filter %}),{% date_start previous_period_filter %} )
THEN 'Previous Period'
END
ELSE
'This Period'
END ;;
}