Beruflich Dokumente
Kultur Dokumente
SCDs are well documented in data warehousing literature. Ralph Kimball has been
particularly influential in describing dimensional modeling techniques for SCDs (see The
Data Warehouse Toolkit, for example). Kimball has further coined different distinctions
among ways to handle SCDs in a dimensional model. For example, a Type I SCD presents
only the current view of a dimensional relationship, a Type II SCD preserves the history of a
dimensional relationship, and so forth.
Example
The discussion below is based on an example sales organization that changes slowly in
time as the territories are reorganized, e.g., Sales Reps switch Districts in time.
One of the capabilities available with slowly changing dimensions is the ability to perform
either "as-is" analysis or "as was" analysis.
As-is analysis presents a current view of the slowly changing relationships, i.e.,
displays sales by District according to the way Districts are organized today.
As-was analysis presents an historical view of the slowly changing relationships,
i.e., displays sales by District according to the way Districts were organized today at
the time the sales transactions occurred.
The techniques described here provide the flexibility to perform either type of analysis.
They also provide an easy way for end users to specify which type of analysis they would
like to perform.
One way to physically store a SCD is to employ Effective Date and End Date columns that
capture the period of time during which each element relationship existed. In the example
below, Sales Rep Jones moved from District 37 to District 39 on 1/1/2004 and Kelly moved
from District 38 to 39 on 7/1/2004:
LU_SALES_REP
FACT_TABLE
LVW_CURRENT_ORG
select sales_rep_id, district_id
from LU_SALES_REP
where END_DT = '12/31/2099'
Create another logical view that performs the "as-was" join between the lookup table and
fact table, resulting in a fact view at the District level. Note that the resulting view is an "as-
was" or historical view: it captures the Sales Rep-District relationships that existed at the
time the transactions occurred:
LVW_HIST_DISTRICT_SALES
select district_id, trans_dt, sum(sales) sales
from LU_SALES_REP L
join FACT_TABLE F
on (L.sales_rep_id = F.sales_rep_id)
where F.trans_dt between L.EFF_DT and L.END_DT
group by district_id, trans_dt
As-Was Analysis
Users specify as-was analysis by using the Historical District attribute on reports:
Report definition:
Resulting SQL:
Report results:
As-Is Analysis
Users specify as-is analysis by using the Current District attribute on reports:
Report definition:
Resulting SQL:
Report results:
A more flexible way to physically store a SCD is to employ surrogate keys and introduce
new rows in the dimension table whenever a dimensional relationship changes. Another
common characteristic is to include an indicator field that identifies the current relationship
records. An example set of records is shown below.
LU_SALES_REP
FACT_TABLE
sales_rep_cd Sales
1 100
2 200
3 150
5 200
2 250
3 300
2 125
6 275
4 150
Specifying the MicroStrategy Schema
Create a logical view to represent only the current District-Sales Rep relationship:
As-Was Analysis
Report definition:
Resulting SQL:
Report results:
As-Is Analysis
Report definition:
Report results: