Fact Tables in Data Warehousing

Fact tables are the central tables in a dimensional model. They contain the measurements or metrics that businesses want to analyze. These metrics are often additive, meaning they can be summed across various dimensions.

Understanding Fact Tables

A fact table typically resides at the intersection of multiple dimension tables. Each row in a fact table represents a specific business event or transaction. The columns in a fact table can be broadly categorized into:

Types of Fact Tables

Fact tables can be classified based on the granularity of the data they store and how they handle changes over time:

Granularity

Granularity defines the lowest level of detail in a fact table. It's crucial to define granularity clearly, as it impacts the data volume, performance, and analytical capabilities. Examples include:

Example Fact Table: Sales Facts

Consider a retail sales data warehouse. A SalesFact table might look like this:

Column Name Data Type Description
DateKey INT Foreign key to the DimDate table.
ProductKey INT Foreign key to the DimProduct table.
StoreKey INT Foreign key to the DimStore table.
CustomerKey INT Foreign key to the DimCustomer table.
SalesAmount DECIMAL(10,2) The total amount of the sale.
QuantitySold INT The number of units sold.
DiscountAmount DECIMAL(10,2) The amount of discount applied.

In this example:

Important: Fact tables should primarily contain numeric measures and foreign keys. Avoid storing descriptive text directly in fact tables, as this can lead to redundancy and performance issues. Descriptive attributes belong in dimension tables.

Factless Fact Tables

Some fact tables, known as "factless fact tables," do not contain any numeric measures. Instead, they are used to record the occurrence of an event or to link dimensions. Common uses include tracking:

For example, a table tracking student attendance might only have keys for StudentKey, DateKey, and CourseKey, indicating that a student attended a specific course on a specific date.

Tip: When designing fact tables, ensure that the measures are additive or semi-additive. Non-additive measures (like ratios that cannot be summed) are generally handled differently, often calculated at query time or stored in specific dimension tables.

Fact tables are the heart of a data warehouse, providing the quantitative data necessary for business intelligence and decision-making. Their design, granularity, and the types of measures they contain are critical for the overall effectiveness of the data warehouse.