Originally published on ColleenMorrow.com.
This post is part of a series on implementing a data warehouse with Microsoft SQL Server 2012. So far, we’ve covered:
Today we’re exploring fact tables in more depth. If you’ll recall fact tables store the quantitative data that lies at the heart of the data warehouse. Without fact tables, our data warehouse would really just be a bunch of mostly unrelated dimension tables, and how boring would that be?
Just like dimension tables, fact tables have their own column types. They are:
- Foreign Keys – As in an OLTP database, foreign key columns reference primary key values in the dimension tables with which our fact table is associated. In the FactInternetSales table, these would include ProductKey, CustomerKey, and OrderDateKey, among others.
- Business Keys – This is usually used as a surrogate key from the table we’re using as our primary source for this fact table. They’re not strictly necessary, but they make it easy to compare and link back to the source data. For example, the SalesOrderNumber and SalesOrderLineNumber columns comprise a composite surrogate key in the FactInternetSales table. They were pulled from the OrderDetails source table.
- Lineage columns – Just as with dimension tables, these are strictly for auditing purposes.
- Measures – These columns store measurements of interest associated with a business process. I’m talking about columns like SalesAmount, OrderQuantity, etc. They are the root of our fact table and the values we’re going to aggregate for reporting. Therefore, they’re usually of a numeric data type.
The primary benefit of a data warehouse is the ability to aggregate data for reporting, forecasting, etc. We don’t often report row-level information, rather we want to be able to slice and dice sales by quarter, by region, by product type, etc. So when we design our fact tables and start adding measures, we need to keep in mind how those measures will be aggregated. Because sometimes how we aggregate a particular measure will depend on what dimension we’re looking at.
For some measures, it’s pretty straightforward. When it comes to a measure like sales amount, we can sum it by date, by region, by product type. If a measure can be summed across all dimensions, it’s referred to as an additive measure.
Sometimes, however, we can sum a measure across all dimensions except for time. An example of this is a balance amount. If Bob has $2000 in his checking account and Betty has $3000, then we can sum across the customer dimension and say that they have a sum of $5000. However, if Bob buys a new laptop today and his checking account balance drops to $500, Bob obviously doesn’t have $2500 total. We can’t sum the account balance across the time dimension. We would need to do something like take the average instead, or simply use the last value. Measures like this are called semi-additive measures.
Finally, some measures can’t ever be summed. These are called non-additive measures, and include measures like discount percentages and prices.
In this installment, we reviewed the different types of fact columns and the additivity of measures. Next time, we’ll talk about implementing fact and dimension tables in the data warehouse.
About the Author
Colleen Morrow is SQL Server Consultant at UpSearch.
Colleen is a database strategist, community advocate, author, blogger and public speaker. She is passionate about helping technology leaders use Microsoft’s SQL Server to protect, optimize and unlock data’s value.
Colleen has been working with relational database for almost 20 years. Since 2000, Colleen has specialized in SQL Server and Oracle database management solutions. She excels at performance tuning, troubleshooting mission critical SQL Server environments, and training technology professionals and business users of all levels.
Since 2011, Colleen has maintained a SQL Server focused blog at http://colleenmorrow.com. She is an active member of the Ohio North SQL Server User Group, as well as a volunteer for the Professional Association for SQL Server (PASS). Colleen earned a Bachelor of Science in Computer and Information Systems from Cleveland State University.
Learn more about Colleen Morrow at //colleen-morrow/.