You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: design-patterns/design-pattern-generic-date-math.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ Creating Dimensions from a Data Vault model essentially means joining the variou
21
21
Figure 1: Example Data Vault model
22
22
Creating dimensions by joining tables with history means that the overlap in timelines (effective and expiry dates) will be ‘cut’ in multiple records with smaller intervals. This is explained using the following sample datasets, only the tables which contain ‘history’ are shown.
23
23
24
+
```
24
25
SAT Product
25
26
26
27
Key|Product Name|Effective Date|Expiry Date
@@ -39,6 +40,7 @@ Product Key
39
40
Channel Key
40
41
Effective Date
41
42
Expiry Date
43
+
```
42
44
43
45
This set indicates that the product has been moved to a different sales channel over time.
44
46
@@ -58,10 +60,7 @@ This set indicates that the product has been moved to a different sales channel
58
60
04-03-2011
59
61
31-12-9999
60
62
61
-
When merging these to data sets into a dimension the overlaps in time are calculated:
62
-
63
-
Business Insights > Design Pattern 019 - Creating Dimensions from Hub tables > BI8.png
64
-
Figure 2: Timelines
63
+
When merging these to data sets into a dimension the overlaps in time are calculated.
65
64
66
65
In other words, the merging of both the historic data sets where one has 4 records (time periods) and the other one has 3 records (time periods) results into a new set that has 6 (‘smaller’) records. This gives the following result data set (changes are highlighted):\
67
66
Dimension Key
@@ -72,6 +71,7 @@ Effective Date
72
71
Expiry Date
73
72
1
74
73
73
74
+
75
75
-
76
76
-1
77
77
01-01-1900
@@ -108,6 +108,8 @@ Cheese-Gold
108
108
31-12-9999
109
109
110
110
This result can be achieved by joining the tables on their usual keys and calculating the overlapping time ranges:
111
+
112
+
```
111
113
SELECT
112
114
B.PRODUCT_NAME,
113
115
C.CHANNEL_KEY,
@@ -137,6 +139,7 @@ WHERE
137
139
THEN B.EXPIRY_DATE
138
140
ELSE D.EXPIRY_DATE -- smallest of the two expiry dates
139
141
END)
142
+
```
140
143
141
144
## Implementation guidelines
142
145
The easiest way to join multiple tables is a cascading set based approach. This is done by joining the Hub and Satellite and treating this as a single set which is joined against another similar set of data (for instance a Link and Link-Satellite). The result of this is a new set of consistent timelines for a certain grain of information. This set can be treated as a single set again and joined with the next set (for instance a Hub and Satellite) and so forth.
0 commit comments