Does it belong in the stage tables or fact tables?

View previous topic View next topic Go down

Does it belong in the stage tables or fact tables?

Post  kskistad on Thu Sep 10, 2009 12:37 pm

If I have a fact table with a "counter" fact, for example a customer places an order, but then goes back and changes parts of that order any number of times, I want to store how many times the customer changed his/her order. The grain of the fact table is the orderID. The changes are captured at the source in a change history table, but that table only stores the previous 5 days changes.

I see two ways to do this: create another table, a factless fact table, and capture the history of changes going forward. Use this table to count the # of changes and update the result in the Orders fact table.

Or, alternatively I could load a persisted staging table with the history of changes, and use that to update my fact table counter. This approach is cleaner in that it doesn't involve a separate fact table that only serves the purpose of updating another fact table row, as users will never query the factless fact table directly (or indirectly) because they are only interested in the # of changes, not each individual change.

What are your recommendations?

kskistad

Posts : 11
Join date : 2009-02-03

View user profile

Back to top Go down

Re: Does it belong in the stage tables or fact tables?

Post  ngalemmo on Thu Sep 10, 2009 1:18 pm

Why not store net changes in the order fact table itself?
avatar
ngalemmo

Posts : 3000
Join date : 2009-05-15
Location : Los Angeles

View user profile http://aginity.com

Back to top Go down

Re: Does it belong in the stage tables or fact tables?

Post  kskistad on Thu Sep 10, 2009 7:27 pm

Well, the # changes will be stored in the fact table itself, but we need to capture the history and store it somewhere in case the fact table needs to be reloaded or adjusted for whatever reason. The source only keeps 5 days of changes, so that wouldn't be accurate if we report changes on a monthly or yearly level.

As an example, if we store it in the Order fact only, say 30 changes for a particular order, and if the current day load had 4 changes, we could update the row to 30 + 4 or 34 changes. But if the business came back and told us, "there was a operational error in the source system that was double counting the changes from Jan 15th through Jan 30th, so adjust your figures to 1/2 for that date range." If we didn't store the history anywhere, we would never be able to know how many changes occurred during those dates; only the total changes to-date.

kskistad

Posts : 11
Join date : 2009-02-03

View user profile

Back to top Go down

Re: Does it belong in the stage tables or fact tables?

Post  ngalemmo on Mon Sep 14, 2009 1:45 pm

I have not seen a situation where the business wanted that level of detail. Given the situation you describe, a separate fact table logging every known change would be the way to go.
avatar
ngalemmo

Posts : 3000
Join date : 2009-05-15
Location : Los Angeles

View user profile http://aginity.com

Back to top Go down

Re: Does it belong in the stage tables or fact tables?

Post  alex.caminals on Fri Sep 18, 2009 4:02 am

I agree with ngalemmo. In fact, now you have a fact table where the granularity is an Order. If you want to keep track of the changes done in each order, the granularity of this fact table becomes "each change in an existing order (or the creation of the order initially)". So that becomes another fact table.

Also, having this new fact table can be useful at some point to analyse the reason of the changes in the orders, such as part changes, promotion code, expected delivery date, etc.

Best regards,
avatar
alex.caminals

Posts : 15
Join date : 2009-02-25
Age : 41
Location : Barcelona (Spain)

View user profile

Back to top Go down

Re: Does it belong in the stage tables or fact tables?

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum