Skip to content

Commit 095f48d

Browse files
authored
Update design-pattern-generic-date-math.md
1 parent 8a3c861 commit 095f48d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

design-patterns/design-pattern-generic-date-math.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Creating Dimensions from a Data Vault model essentially means joining the variou
2121
Figure 1: Example Data Vault model
2222
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.
2323

24+
```
2425
SAT Product
2526
2627
Key|Product Name|Effective Date|Expiry Date
@@ -39,6 +40,7 @@ Product Key
3940
Channel Key
4041
Effective Date
4142
Expiry Date
43+
```
4244

4345
This set indicates that the product has been moved to a different sales channel over time.
4446

@@ -58,10 +60,7 @@ This set indicates that the product has been moved to a different sales channel
5860
04-03-2011
5961
31-12-9999
6062

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.
6564

6665
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):\
6766
Dimension Key
@@ -72,6 +71,7 @@ Effective Date
7271
Expiry Date
7372
1
7473
73
74+
7575
-
7676
-1
7777
01-01-1900
@@ -108,6 +108,8 @@ Cheese-Gold
108108
31-12-9999
109109

110110
This result can be achieved by joining the tables on their usual keys and calculating the overlapping time ranges:
111+
112+
```
111113
SELECT
112114
B.PRODUCT_NAME,
113115
C.CHANNEL_KEY,
@@ -137,6 +139,7 @@ WHERE
137139
THEN B.EXPIRY_DATE
138140
ELSE D.EXPIRY_DATE -- smallest of the two expiry dates
139141
END)
142+
```
140143

141144
## Implementation guidelines
142145
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

Comments
 (0)