Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Slowly Changing Facts


Slowly Changing Facts

Author
Message
jcraigue@cox.net
jcraigue@cox.net
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 34
Please please please refer to these sorts of articles as 'techniques' or 'methods' or 'solutions' -valuable mind you, but 'design pattern' mens something quite specific, and strategies for using sql and related tools ain't it

A minor point, but not everything is a 'design pattern', nor does it need to be to be useful.

Just trying to prevent more abuse of the language...
PHYData DBA
PHYData DBA
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 533
Rexell (12/13/2012)
Can you let me know if you know of any other legitimate reasons for implementing this solution or of any other potential pitfalls you may have seen when implementing it in the past please? Thanks.

I can tell you this kind of type 1 and type 2 transactional fact table data update collection is so popular now that M$ put CDC into SQL 2008 to make it easier to track and load into Data Warehouses and what I like to call Data Audit Warehouses.
Of course most anyone that is not the lead DBA or in executive management will see the goodness the provides.
PHYData DBA
PHYData DBA
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 533
markoos1 - Great article. That is all ;-)
Cool
PHYData DBA
PHYData DBA
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 533
psychodba (4/17/2012)
I dont see any easy way to maintain AVG measures in this model. We need two layers of aggregations.
SUM to construct the full amount and only then AVG. This is not possible for some applications.

In what way do you see this? Sorry but I cant see your point.
sneumersky
sneumersky
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2162 Visits: 487
Good article.

There is no "right" or "wrong" way to handle this; however, this methodology (ledgering changes) has two main advantages:

1. Complete auditability and data transparency.
2. Allows for incremental processing of multidimensional Analysis Services cubes instead of an expensive full reprocessing of a cube.

No solution is without risk.

Steven Neumersky, CBIP, MCITP
PHYData DBA
PHYData DBA
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 533
sneumersky (10/18/2013)

2. Allows for incremental processing of multidimensional Analysis Services cubes instead of an expensive full reprocessing of a cube.

It is obvious you have been there and come back with knowledge.
Thank you for sharing!
PHYData DBA
PHYData DBA
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 533
jcraigue@cox.net (10/18/2013)

A minor point, but not everything is a 'design pattern', nor does it need to be to be useful.
Just trying to prevent more abuse of the language...

Design Pattern has to be the new red headed step child of Software Architecture Language. It seems to be abused and used in the wrong way more than "Extreme Application Development".
psychodba
psychodba
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 8
Let's assume we don't use SCD2 on the fact table.
ID SalesPersonID ProductID SaleMonth Quantity Revenue
1 101 1001 2012-01 10 100
2 101 1002 2012-01 4 64
3 101 1003 2012-01 3 36

Then we bring the table to some Reporting tool like BO, OBIEE, Cognos.
We define the aggregates:
SUM(Revenue) Revenue_SUM,
AVG(Revenue) Revenue_AVG

Now users can design the report by grabbing these elements:
SalesPersonID, SaleMonth, Revenue_Revenue_SUM, Revenue_AVG
This will be the average of all sales per Month and Person.

Reporting tool will generate a query like this:
SELECT SalesPersonID, ProductID, SaleMonth, SUM(Revenue), AVG(Revenue)
FROM fact.SalesDetail
GROUP BY SalesPersonID, ProductID, SaleMonth.

Statistics: 3 deals, 3 products, total quantity 17
Revenue_SUM will be (100+64+36) =200
Revenue_AVG will be (100+64+36)/3 =66.67


Now, let's assume there was a mistake in the source and it's corrected with SCD2.
ID SalesPersonID ProductID SaleMonth Quantity Revenue Audit SourceID
1 101 1001 2012-01 20 200 1 1
2 101 1002 2012-01 4 64 1 2
3 101 1003 2012-01 3 36 1 3
4 101 1001 2012-01 -10 -100 2 1


Statistics: 3 deals, 3 products, total quantity 17
Revenue_SUM will be (200-100+64+36) =200
Revenue_AVG will be (200-100+64+36)/4 =50

It's all the same, but AVG is wrong.

Well, it's still possible to figure out some of these aggregates.
For Revenue_AVG would be:
SUM(Revenue) / (COUNT(*) - COUNT(DISTINCT Audit) +1)

Would you be able to write one to show the MIN (Revenue) ?
In this case you need to SUM first to get the full amounts and only then do the MIN.
This is not doable using Reporting GUI for ordinary users.

I don't even dare to think of some more complicated analytical functions here like RunningTotals and etc.
Luckily there are other better solutions.
scrrbiswas
scrrbiswas
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 31
This topic itself is nice and the techniques mentioned in this article can be used in many occasions.

However "change a dimension ID to see what happens" section does not cover the situation when the staging fact table already has a transaction (record) with same sale person id , product id and date.

The following update statement will create a record with a duplicate key (100, 1004, 20101102), if allowed.

UPDATE staging.SalesDetailSource
SET SalesPersonID = 100
WHERE ProductID = 1004
AND SalesPersonID = 101
AND SaleDate = 20101102;

Any explanation on how to handle this situation will be interesting.

Thanks.
PHYData DBA
PHYData DBA
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 533
scrrbiswas (10/28/2013)
This topic itself is nice and the techniques mentioned in this article can be used in many occasions.

However "change a dimension ID to see what happens" section does not cover the situation when the staging fact table already has a transaction (record) with same sale person id , product id and date.

The following update statement will create a record with a duplicate key (100, 1004, 20101102), if allowed.

UPDATE staging.SalesDetailSource
SET SalesPersonID = 100
WHERE ProductID = 1004
AND SalesPersonID = 101
AND SaleDate = 20101102;

Any explanation on how to handle this situation will be interesting.

Thanks.

Depends on if you want a Historical record for this dimension table update.
Is this just a situation where you want to update the Business Key Id in the dim table when it changes in the source?
Maybe some details on what is a Suragate Key and a Business Key in your statement above?
You are using Suragate keys in your Dimension tables right?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search