In a dimension model, a fact table stores measures associated with events. It can store data such as sales orders, inventory balances, exchange rates, and temperature readings.
Fact tables contain columns of indicator values (typically numeric), for example, sales order quantity, which can be summarized (by using the sum, count, average, and other functions) by dimension and group during analysis and querying.
Fact tables also include dimension keys, which determine the dimensions of facts. The dimension key values determine fact granularity (which is the most detailed level at which facts can be defined). For example, the Order Date dimension key in Sales Fact Table enables date-level fact definition, while the Target Date dimension key in Sales Target Fact Table enables quarter-level fact definition.
To easily identify fact tables, you need to prefix their names with f_ or Fact_ typically.
Fact Table Structure
In this example, the fact table does not have a primary key. This is because a primary key typically serves no practical purpose and would unnecessarily increase the storage overhead of the table. A primary key of a fact table is usually represented by a combination of dimension keys and attributes.
The fact table in this example contains various dimension keys, which determine the dimensions of the fact table. Dimension keys are foreign keys that reference surrogate keys (or higher-level attributes) in related dimension tables.
A fact table can reference the same dimension repeatedly. In this case, the dimension is called a role-playing dimension. In this example, the fact table includes the OrderDate_Date_FK and ShipDate_Date_FK dimension keys. Each dimension key represents a distinct role, but both physically point to the same date dimension table.
You are advised to define every dimension key as NOT NULL.
The fact table in this example includes one attribute. Attributes provide additional information and specify the granularity of fact data, yet they are neither dimension keys, dimension attributes, nor measures. In this example, the attribute column stores sales order information. In other examples, attribute columns may include tracking numbers or ticket numbers. For analysis purposes, an attribute may form a degenerate dimension.
The fact table in this example also contains measures, for example, the Quantity column. Measure columns are typically numeric and commonly additive (meaning they can be aggregated using functions such as SUM and other summary operations).
The fact table in this example also includes various audit attributes. Audit attributes are optional. They allow you to track when and how fact records were created or modified, and may include diagnostic or troubleshooting information generated during Extract, Transform, and Load (ETL) processes. For instance, they can record which user or process updated a row and when the update occurred. Audit attributes can also help you diagnose challenging issues, for example, when an ETL process stops unexpectedly.
There are three types of fact tables:
Transaction fact table
Periodic snapshot fact table
Accumulating snapshot fact table
A transaction fact table stores business events or transactions. Each row stores facts represented by dimension keys and measures, and optional additional attributes. All data is fully known when inserted, and never changes (unless correcting errors).
Typically, transaction fact tables store facts at the lowest possible level of granularity, and contain measures that are additive across all dimensions. For example, a sales fact table that stores every sales order rows is a transaction fact table.
A periodic snapshot fact table stores measures at predefined time or specific intervals. It summarizes key indicators or performance indicators over a period, making it highly useful for trend analysis and monitoring change over time. Measures are always semi-additive.
The inventory fact table, which is loaded daily with end-of-day inventory balance of every product, serves as a good example of a periodic snapshot table.
When recording large volumes of transactions is expensive and does not support useful analytical requirements, periodic snapshot tables can be used instead of transaction fact tables. For example, there may be millions of inventory movements in a day (which can be stored in a transaction fact table), but your analysis may focus only on trends of end-of-day inventory levels.
An accumulating snapshot fact table stores measures that accumulate across specifically defined periods or workflows. It typically records the state of a business process at distinct stages or milestones, which may take days, weeks, or even months to complete.
A fact data row is loaded soon after the first event in a process, and is updated in a predictable sequence every time a milestone event occurs. Updates continue until the process completes.
An accumulating snapshot fact table includes multiple date dimension keys, each representing a milestone event. Measures typically record durations.
Measures are typically numeric and commonly additive. However, some measures can not always be added. Such measures are considered semi-additive or non-additive.
Additive Measure
An additive measure can be summed across any dimension. For example, order quantity and sales revenue are additive measures (providing that revenue is recorded for a single currency).
Semi-Additive Measure
A semi-additive measure can be summed across certain dimensions only.
The following are some examples of semi-additive measures:
A measure in a periodic snapshot fact table cannot be summed across periods of time. For example, you should not sum the age of an inventory item sampled nightly, but you can sum the age of all inventory items on a shelf every night.
An inventory balance measure in an inventory fact table cannot be summed across products.
Sales revenue in a sales fact table with a currency dimension key cannot be summed across currencies.
Non-additive Measure
A non-additive measure cannot be summed across any dimension. For example, adding a temperature reading to other readings is meaningless in essence.
For other examples, including rates, such as unit prices and ratios, you are advised to store the values used to compute the ratio. In this case, the ratio can be calculated if needed. For example, a discount percentage of a sales fact can be stored as a discount amount measure (to be divided by the sales revenue measure). Similarly, you should not sum the age of an inventory item on the shelf over time, but you can observe a trend in the average age of inventory items.
While some measures cannot be summed, they are still valid. They can be aggregated by using count, distinct count, minimum, maximum, average, and other functions. Non-additive measures can become additive when used in calculations. For example, while the unit price itself cannot be summed, the sales revenue produced by multiplying it by the order quantity is additive.
A fact table that contains no measure columns is referred to as a factless fact table. A factless fact table typically records events or occurrences, for example, student attendance records. From an analytical perspective, indicators can be created by aggregating fact table rows.
An aggregate fact table represents a summarized version of a base fact table, created by reducing dimensionality and/or increasing granularity. The aim is to accelerate query performance for commonly queried dimensions.
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
Submitted successfully
Network busy