{"id":275,"date":"2023-11-24T11:09:57","date_gmt":"2023-11-24T10:09:57","guid":{"rendered":"https:\/\/bitwise.exposed\/?p=275"},"modified":"2026-03-16T09:38:48","modified_gmt":"2026-03-16T08:38:48","slug":"facts-and-dimensions","status":"publish","type":"post","link":"https:\/\/bitwise.exposed\/index.php\/2023\/11\/24\/facts-and-dimensions\/","title":{"rendered":"Facts and Dimensions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduciton<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Facts<\/mark> in a database context are the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">measurable and numeric<\/mark> data and the foundation for key performance indicators or business metrics. They provide the quantitative details that businesses analyze to gain insights into their operations. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Dimensions<\/mark>, on the other hand, are <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">descriptive attributes<\/mark> or categories that provide context to the facts. They offer a way to categorize <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">and filter the data in the fact table<\/mark>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">dimensional model<\/mark>, such as a star schema, facts are stored in the central fact table, while dimensions are stored in separate dimension tables. Together, facts and dimensions form the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">foundation for<\/mark> effective <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">data warehousing and business intelligence<\/mark>, enabling users to conduct meaningful analyses and gain a comprehensive understanding of their business data.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Fact Tables<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">fact table<\/mark> serves as a repository for <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">quantitative data<\/mark>, commonly referred to as measures or metrics, that represent the essential business facts. Key considerations and guidelines for defining fact tables:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"surrogatekeysintro\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Granularity:<\/mark><br>    Fact tables should be defined at the <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">finest level of detail<\/mark>, representing the lowest level of information that is of interest for analysis. This is known as the granularity of the fact table.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Additive Measures:<\/mark><br>    Fact tables <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">should primarily contain additive measures<\/mark>. Additive measures are those that can be summed up across all dimensions. For example, sales revenue is an additive measure because you can sum it across various dimensions like time, geography and product.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Numeric Values:<\/mark><br>    Fact tables <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">should primarily store numeric values<\/mark>, representing measurable quantities, like sales revenue, quantity sold and profit.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Foreign Keys to Dimension Tables:<\/mark><br>    Fact tables include foreign keys that establish relationships with dimension tables. These foreign keys link the fact table to the descriptive attributes stored in dimension tables. These relationships <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">enable users to analyze and filter data by various dimensions<\/mark>.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Date and Time Stamps:<\/mark><br>    Fact tables often include date and time stamps to capture when the business events or transactions occurred. This <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">supports time-based analysis<\/mark>, such as trend analysis or comparisons across different time periods.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Surrogate Keys:<\/mark><br>    It is common to use surrogate keys in fact tables. Surrogate keys are <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">system-generated keys<\/mark> that uniquely identify each row in the fact table. These keys provide a stable reference point for relationships with dimension tables.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Degenerate Dimensions<\/mark>:<br>    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">Fact tables may include <\/mark>degenerate dimensions, which are <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">attributes<\/mark> that would <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">normally be part of a dimension<\/mark> but are instead included in the fact table due to their simplicity or high cardinality. An example is an invoice number.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Snapshot Fact Tables vs. Transaction Fact Tables:<\/mark><br>    Fact tables can be categorized into snapshot and transaction types. Snapshot fact tables capture a snapshot of business <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">metrics at a specific point in time<\/mark>, while transaction fact tables record <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">individual business events or transactions<\/mark>.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-primary-color\">Sparse Data:<\/mark><br>    Fact tables are often sparse, meaning that <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">not every combination of dimension keys has a corresponding fact record.<\/mark> This is typical in scenarios where certain measures are not applicable for every combination of dimensions. For example, consider a fact table that tracks sales data with dimensions for time, product, and geography. If there are no sales for a particular product in a specific month and region, there may be no entry in the fact table for that combination of dimension keys. This is an example of sparse data. Managing sparse data efficiently is important for optimizing storage, improving query performance, and ensuring that analysis tools can navigate the data effectively. (Practice example: reduced history in fact table without limiting the dimensions as well.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following these guidelines or concepts, is a good starting point to create fact tables that are well-structured and optimized for analytical queries, supporting flexible and intuitive analysis of business data in a dimensional data warehouse environment.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Dimension Tables<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Dimension tables<\/mark> in a database <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">contain descriptive attributes that provide context to the quantitative data stored in the fact table(s)<\/mark>. These attributes categorize and organize the facts, offering a way to analyze and filter data along different axes. In a star schema, dimension tables surround the central fact table(s), forming a star-like structure. Each dimension table typically corresponds to a specific aspect of business, such as time, geography or product and holds the descriptive details related to that aspect. The relationship between the fact table and dimension tables is established through foreign key links, allowing users to navigate and analyze data across various dimensions in an efficient and intuitive manner for business intelligence purposes. Key considerations and guidelines for defining dimension tables:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Surrogate Keys:<\/mark><br>    It&#8217;s recommended using surrogate keys in dimension tables. Surrogate keys are <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">system-generated<\/mark>, <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">unique<\/mark> <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">identifiers<\/mark> <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">that provide stability<\/mark> and consistency, even if the source system keys change.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Descriptive Attributes:<\/mark><br>    Dimension tables should include descriptive attributes that help categorize and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">describe the business entities<\/mark> represented <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">in the fact table<\/mark>. Examples of dimension attributes are product names customer names or geographic locations.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Hierarchies:<\/mark><br>    Dimension tables may include hierarchies to <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">represent relationships between different levels of granularity within a dimension<\/mark>. For example, a time dimension might have hierarchies such as year, quarter, month and day.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Slowly Changing Dimensions (SCD):<\/mark><br>    The concept of Slowly Changing Dimensions (SCD), recognizing that <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">dimension attributes may change over time<\/mark>. Dimension tables could accommodate different SCD types, such as Type 1 (overwrite), Type 2 (add a new record), and Type 3 (add a new attribute). E.g. Change the name of a brand like Raiders and Twix, or a customer has a new address.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Data Quality:<\/mark><br>    Ensuring data quality in dimension tables is emphasized.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\"> Validating and cleansing dimension data to maintain accuracy and consistency <\/mark>in reporting and analysis in mandatory.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Denormalization:<\/mark><br>    Dimension tables are denormalized to some extent to simplify queries and improve performance. <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">Redundant information is allowed to avoid complex joins<\/mark> when querying the data.<br><br><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Integrity Constraints:<\/mark><br>    Integrity constraints refer to <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-variant-text-accent-color\">rules or conditions that are enforced to maintain the accuracy, consistency, and reliability of the data.<\/mark> These constraints help ensure that the data in dimension tables adheres to the specified business rules and relationships. Here are some common integrity constraints applied to dimension tables:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Primary Key Constraint: The primary key constraint ensures that each record in the dimension table is uniquely identified. It typically involves a unique identifier, often referred to as a surrogate key, which ensures that there are no duplicate records.<\/li>\n\n\n\n<li>Foreign Key Constraint: Foreign key constraints establish and enforce relationships between the dimension table and the fact table. The foreign key in the fact table links to the primary key in the dimension table, maintaining referential integrity.<\/li>\n\n\n\n<li>Domain Integrity: Domain integrity constraints define the permissible values for columns in the dimension table. For example, if a dimension represents product categories, the domain integrity constraint ensures that only valid categories are entered.<\/li>\n\n\n\n<li>Not Null Constraint: This constraint ensures that certain attributes in the dimension table, which are essential for analysis and reporting, cannot have a null (missing) value. It helps prevent incomplete or inconsistent data.<\/li>\n\n\n\n<li>Unique Constraint: The unique constraint ensures that specific columns or combinations of columns in the dimension table have unique values. This can be used to enforce uniqueness on natural keys or other business-specific attributes.<\/li>\n\n\n\n<li>Check Constraint: Check constraints define conditions that the data in the dimension table must meet. For instance, a check constraint might ensure that the start date of a dimension record is earlier than the end date.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-surface-brand-secondary-color\">Defaults and Unknowns:<\/mark><br>    It can also be useful to handle default values and unknowns in dimension tables to account for missing or unspecified information. This could imporve developing speed and improve flexibility. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following these guidelines or concepts, is a good starting point to create dimension tables that are well-structured, stable and flexible entities that provide valuable context for analyzing business metrics within a dimensional data warehouse, particularly in the context of a star schema.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fact tables serve as the central repository for business facts, while dimension tables categorize and add meaning to the data through descriptive attributes, forming a key component of dimensional modeling in business intelligence.<\/p>\n","protected":false},"author":1,"featured_media":292,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"[]"},"categories":[19],"tags":[],"class_list":["post-275","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-warehouse"],"_links":{"self":[{"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":15,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions\/474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/media\/292"}],"wp:attachment":[{"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitwise.exposed\/index.php\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}