Dimensional modeling – architecture and terminology

by Joakim Dalby (danish Dimensionel modellering, Datamodellering, Data varehus)

 

1. Introduction

Data Warehouse is

 

·  Subject-oriented because collect business data from a variety of source systems.

·  Integrated because using common and consistent business names and units.

·  Time-variant because historical data is kept as current data at any given time.

·  Non-volatile because data do not change or historical data will never be altered.

·  Enrichment and processing of data for providing new knowledge.

·  Collection of data in support of management's decision making process and analy­zing the business with business performance measurement qualifiers and KPI Key Performance Indicator used as a measure of how a company is doing.

·  Utilizing dimensional modeling, end users and analysts can easily understand and navigate the data structure and fully exploit the data for self-service BI.

·  Goal to support slice and dice of data for business analysis.

·  Driven by business requirements specification from stakeholders and users. A data warehouse must have focus on the needs of the business.

 

Data from different volatile operational source legacy systems are sto­red in tables in a relational database called a data warehouse and it is designed to sup­port reporting and data analyses by a single and common data model that is easy to navigate in. Many operational source legacy systems update its data to reflect the most current and recent state while a data warehouse also maintain history.

 

A Business Intelligence (BI) system provides the information that management ne­eds to make good business decisions and data warehousing is a method to help database designer to build the system e.g. based on Dimensional modeling principles. An OLAP (OnLine Analytical Processing) cube can be at the top of the Dimensional modeling to present data in tools like Excel, Power BI, QlikView, Tableau or Targit.

BI is going from data and information to knowledge and wisdom to the users.

Previously called Decision Support System. BI could also stand for Business Insight.

 

In the article I will focus on the basic concepts, terminology and architecture in Di­men­sio­nal mo­deling. My homepage has other articles of how to design and im­ple­ment a data warehouse system with levels of data in the ETL process (Extracting, Trans­for­ma­tion, Loading). I see Dimensional modeling as a subset of the Entity Re­la­tion­ship (ER) data modeling design method of a rela­tional database system OLTP (On­Line Transaction Processing). Peter Chen, the father of ER modeling said in his seminal paper in 1976: »The entity-relationship model adopts the more natural view that the real world consists of entities and re­la­tion­ships. It incorporates some of the important semantic information about the real world.« Where ER data mo­dels have little or no redundant da­ta, dimensional models typically have a large a­mount of redundant data. Where ER data models have to assemble data from nu­me­rous tables to produce anything of great use, dimensional models store the bulk of their data in the single Fact table or a small number of them and divide data into different databases called Data mart. A data mart contains one data area for one pur­pose and is customized and/or summarized data derived from the data ware­house and tailored to support the specific analytical requirements of a bu­si­ness unit or function. It utilizes a common enterprise view of strategic data and provides business units more flexibility, control and re­spon­sibi­lity. For example: Sales mart, Cu­sto­mer mart, Market mart, Production mart, Inventory mart, Shipment mart.

 

Dimensional modeling approach is a technique that seeks to present data in a stan­dard, intuitive framework of dimension and fact and focuses on ease of end user acces­sibility and provides a high level of performance access to the data ware­house. Kimball recommend in the design of a data warehouse to decide what busi­ness process(es) to model by combining an understanding of the business require­ments with an understanding of the available data.

 

Back in the 1970's William H. Inmon began to define the term data warehouse as a one part of the overall business intelligence system. An enterprise has one data warehouse with entities in a relational model as a centralized repository, and mul­ti­ple data marts which source their information from the data warehouse. In the data warehouse, data is stored in 3rd normal form. Data warehouse is at the center of the Corporate Information Factory (CIF), which provides a logical framework for delivering business intelligence. A data mart is a simple form of a data warehouse that is focused on a single subject. Denormalization and redundancy is the norm for data modeling techniques in a data mart. Ralph Kimball: »A data warehouse is an union of all its data marts.« Kimball’s data warehousing architecture is also known as Enterprise Data Warehouse Bus Architecture (BUS) matrix as a collection of conformed dimensions that has the same meaning to every fact.

 

A table contains Columns also known as Attribu­tes or Fields. Important tip by naming columns, do not use possessive nouns such as Recipient's birth date, better use CamelCase like RecipientBirthDate in a column name, and don’t use values in column name like EmployeeDay/NightCode better with Em­ploy­­ee­­Shift­Type­Code.

 

1.1. Data layer in a dimensional modeling architecture

A description of the content of data layers of the throughput from source legacy systems to business users PC screen for improved analytic decision making.

 

Input data area - IDA

From source legacy systems to Input data area. Also called Raw data, Source, Le­gacy, Capture Operational Data layer, Data Acquisition or Extract. Empty this area before the source fetch ETL process. Datatypes will be adjusted to fit with the receiving database system. Do reconciling between data warehouse and source legacy systems with reconciliation of row count and mark as reconciled and do auditing report. (to reconcile in danish at afstemme, stemmer overens). Maybe a receipt sy­stem where IDA tells the source legacy systems that data has been received. Data might be wrong in input data area or in archive and later source legacy system will resend a new revision of data, therefore important to create output views that filter wrong data away and making correct data as an extraction to the next layer of the data warehouse. Each table has a column IDA_IN­SERT_TIME so all rows in all tables will use the same capture time as a received date that will be used later for e.g. type 2 or 7 ValidFrom and ValidTo date history to be close to the time when data was fetched. IDA_IN­SERT_TIME represents a snapshot of the total amount of data as it look likes in the source systems. IDA_IN­SERT_TIME can be set in a System database when the fetching is starting and ETL jobs/pac­ka­ges/trans­forma­tions/sql will reuse the same time for all data rows. So­me­times a source legacy system has a Changed co­lumn with time of first inserted or time of latest updated data in the row/record that can be used for ValidFrom.

Kimball recommends that source legacy systems express data at the lowest detail possible for maximum flexibility and extensibility to provide the data warehouse for simplicity and ac­ces­sibility and it will be the data warehouse to make summary data, not the ope­ra­tio­nal source data system.

 

Archive - ARC

From Input data area to Archive. Also called Operational Data Store (ODS), Persistent Staging Area (PSA), Persistence Layer, Data Repository or History. Never empty this area because it is archiving of time variant source data and it will retain historical value changes in the source legacy system. Simple data adjustment can be done to gain same date and amount format and same data representation of a social security number etc. but it will be in new columns so the original values are unchanged. Each table has co­lumns e.g., IDA_INSERT_TIME, ARC_INSERT_TIME (datetime2(7) default SYS­DATE­TIME(), not unique per row), ARC_TS (timestamp, rowversion, unique per row), ARC_RECORD_ID (a sequence number per row per table for uni­que­ness) to fetch delta data out of the archive that have not yet been loaded, and maybe an ARC_GLOBAL_ID (unique sequence number per row across all tables). Reasons for having an archive can come from issues of data quality and data governance and external regulations e.g. Sarbanes-Oxley, Basel I, Basel II, HIPAA. Data Vault is one approach of an implementation of an archive as a back-room.

 

Data staging area - DSA

From Archive to Data staging area by extraction to prepare data cleansing, data clea­ning and data scrubbing (e.g. trim string, unicode string, max length of string, null gets a value as 0 or empty string '', replace illegal characters, replace value, ve­ri­fi­cation of data type, data syntax, date format, correcting misspelling, fix im­pos­sible values, punc­tuation and spelling differences), to achieve common format, notation, re­pre­sen­ta­tion, validate data, correct data and data deduplica­tion by selecting one of the duplicate rows and keep the others in a variety table. Data enrichment according to business rules, identify dimension data and fact data with derived values e.g. total cost and re­venue, elapsed time and overdue time. This is the trans­for­ma­tion of data. Empty this area before the ETL process. DSA will perform a data quality and filter wrong data into a quality assurance and quality control (QA/QC) database. DSA continues reconciling data from the archive for re­fe­ren­tial integrity i.e. foreign key value exists as primary key value, re­la­tion­ship cardinality rules for depen­dencies as mandatory, optional or contingent to make sure there is a foreign key or not, it can be null or it needs a value. Many other value checks and summation and so on for a true validation of data. When all tables in this area is loaded with correct data, the DSA is suc­cess­fully completed with ValidFrom and ValidTo based on IDA_IN­SERT_TIME that represent a batch of insertion and mark all data to that batch time no matter which source legacy system data is coming from. All Valid­From will be using the same batch time which is usefull for join between tables and between source legacy systems to fetch the right data shapshot at a particular time back in history. Furthermore is derived co­lumns and cal­cu­la­tions ready for loa­ding to the next layer of the data warehouse. Kimball has called it data wrangling to lasso the data and get it under control (data munging). DSA can also be called Work area or just Staging. (In danish this layer is called tilrettelagt lag eller behandlet lag). Kimball calls this layer ETL-system.

 

Data mart - DMA

From Data staging area to Data mart with dimensional mode­ling, conformed and shared dimension tables, star schema around each fact table, assigned surrogate key (artificial key, i­den­tity column, a unique sequence number) for each dimension and use it in fact as foreign key. When multiple fact tables share dimensions it is called constallation schema or multi-star schema. Keep historical data in dimension and fact with ValidFrom and ValidTo columns. Make it easy for users to search for current data through a view and to give a historical date to a table-valued function to fetch dimension data and fact data at any point of time. A data mart can have multiple fact tables with different granularities. One or multiple fact tables can create extra derived fact table with special calculations and search filter cri­teria to enrich data to match the business requirements spe­cifi­cation. Never empty this area and always back­up before the ETL process. Data mart is a front-room for pu­blis­hing the organization’s data assets to effectively supports improved business decision ma­king. A data mart contains one data area for one purpose and is subject-orien­ted there­fore a data warehouse will consist of many data marts and they will have some common dimensions. To avoid to maintain the same dimension in multiple data marts may it be considered to have a dimension data mart that share its tables through views inside the other data marts. Kimball calls this layer dimensional presentation area and he is using the term first-level for a data mart contains data from only one source legacy system and second-level or consolidated for a data mart with multiple sources to cross business processes.

 

Presentation interface - PIF

From Data mart to Presentation interface through a data access tool or a data visua­liza­tion tool like Ta­bleau, QlikView/Qlik Sense can access data from a di­men­sio­nal schema and OLAP cube loa­ding data from a data mart and display a pivot in Excel, Targit or Po­wer BI for user presen­tation. Fixed report sends out as pdf file to business users every day, week, month and so on. Data mining and machine lear­ning will also use data from a data mart. Percentage (fraction) and ratio based on a dimension slice will be calculated in the tool and a fact table contains a numerator and a denominator, e.g.:

Average price = Sum(Unit price x Quantity) / Sum(Quantity).

Kimball calls this layer Business In­tel­ligen­ce Application.

 

Supporting databases (not part of data layer)

  • Audit with audit trail for reconciliation check, validation check of data from source legacy systems and number of rows in tables and other summarized measures to monitor and control the data quality of the data warehouse and hereby to avoid discrepancy between source legacy systems and the data ware­house. Do alert the users.
  • System with data for the ETL process e.g. connection string and status of execution of job, package, transform etc.
  • Usage with basic data for rules and mappings for the ETL process and with business data for some dimensions e.g. hierarchy, grouping and sort order values etc. maintained and updated by the business users through an ap­pli­ca­tion. Some data in the Usage supporting database will be loaded from the Archive, because the data comes from a source legacy system, to be enriched by the business users. Input data area will fetch data from the Usage sup­por­ting database and further to the Archive to be used in trans­for­ma­tions and updating dimensions with enriched data that doesn't e­xists in the source le­ga­cy systems. Usage data will also be used for making fact data i.e. a cal­cu­la­tion with a constant value and a rule as if-then-else, lookup etc. Usage is data-driven to avoid data values in ETL package and program.
  • Wrong with data that have some errors and do not follow the quality as­su­ran­ce and quality control. Quality assuring and consistency is important parts of the ETL process and the audit trail.

 

1.2. Data capture methods

Data capture from source legacy systems is based on two data flow directions:

 

  • Push where Source find the data and deliver it to an area like a database or a file at ftp and later the Input data area will fetch the data from that area and indicate that the data is downloaded, received and stored, so Source knows that it can make a new delivery by using a semaphore to control access to a common resource by multiple processes.
  • Pull where Input data area will fetch data from Source through a SQL Select From Where statement maybe with joins of tables or using a view or calling a stored procedure with a parameter as a criteria value to limit source data and for doing delta data detection or incremental load. From a ETL tool or a web-service.

 

Granularity of data capture integration strategy is to consider when the amount of data is huge in the source legacy systems. A data warehouse prefer to receive at the lowest granularity level of detail in case of specific analysis usage or data validation, but some­times it is necessary to aggregate and summarize source data to a higher granularity like per day and per customer segment for transaction data or transactional data from an OLTP system e.g. orders, invoices, billings, payments, site hits. Non-transactional data e.g. Customer, Location, Contact, Supplier, Part, Product can be stored in a Master Data Management (MDM) as master entities that is shared with multiple operational applications in the organization or in the company.

 

Data capture from source legacy systems is based on multiple data delivery forms:

 

  • Data rowset, recordset, multiple result sets from a relational database.
  • csv file with a separator like comma or semicolon, maybe with field header.
  • txt file e.g. from Excel save as unicode text with tabular separator.
  • XML, JSON or another data structure.

 

Data capture from source legacy systems is based on two data delivery methods:

 

  • Full dump where Input data area gets all data from Source.
  • Incremental load or delta data detection where Input data area only gets new data or changed data from Source, called Change data capture. Need an Initial load the first time running. It can be Source that keep track of deli­vered date, or it can be Input data area that keep track of a last received Sequence Id (integer), Sequence Time (datetime) or Insert­Update­Time­stamp value from the Source for each data row, so Input can detect new data or changed data like asking for data since that value (Insert­Update­Time­stamp > latest value). It could also be a posting data e.g. entry date (or created date) and next load is for EntryDate > »the last received EntryDate«.

 

It is important to do a log of number of rows/records from the source lega­cy systems to the Input data area for later reconciliation check count auditing (in danish kon­trol­optælling, afstemning) in case a source legacy sy­stem does not deliver the expected number of rows and to monitor over time the number of rows to see if it increases as expected and be used in a graph over the amount of data in the data warehouse. Other data values e.g. amount, quantity and volume can also be logged and monitored. I recommend that source legacy system tells the number of rows per table that will be compared to the saved number of rows in Input data area in an audit trail. It can be implemented as a view in the source legacy system like this:

CREATE VIEW BI_Audit_NumberOfRows AS

SELECT 'Northwind' AS Sourcename, 'Customers' AS Tablename, COUNT(*) AS NumberOfRows

FROM dbo.[Customers]

UNION ALL

SELECT 'Northwind' AS Sourcename, 'Orders' AS Tablename, COUNT(*) AS NumberOfRows

FROM dbo.[Orders]

UNION ALL

SELECT 'Northwind' AS Sourcename, 'Order Details' AS Tablename, COUNT(*) AS NumberOfRows

FROM dbo.[Order Details]

 

The data warehouse can also do its own delta data detection between Input data area and Archive to identify new data, changed data and deleted data to maintain historical data with ValidFrom and ValidTo datetimestamps is handled by following actions:

 

  • which rows is new and give them a CreatedDateTime or an Inserted­Date­Time or a flag N for new.
  • which rows has been changed and give them a ModifiedDateTime or a Last­Updated­Date or a flag C for changed or U for updated.
  • which rows has been deleted and give them a DeletedDateTime or a flag D for deleted.

 

Sometimes the source legacy system provides a flag information like N for new data, C for changed data and D for deleted data.

I seen pair as: New – Changed, Created – Modified or Insert – Update.

 

Sometimes the source legacy system update a data row multiple times but only the most recent version goes to the data warehouse. If source legacy system insert and update a row before a new load to data warehouse, only the updated version goes to data warehouse. If source legacy system insert a new row and delete the same row before a new load to data warehouse, the data will never goes to data warehouse. It is seldome that a source legacy sy­stem has a log and is logging all changes with a revision nummer or a ValidFrom and ValidTo date­time­stamps, therefore a data warehouse does not contains 100% full historical updates of data in an organization. Sometimes a source legacy system has for each (or selected) tables in the database an extra historical log audit table (shadow table) that contains all inserted, updated and deleted data rows from the original table together with an Action column (values for Insert, Update, Delete) and an EntryDate date­time­stamp column that mark when the action was occurred and a SequenceId that is used for delta data detection to pull data from Source log to Input data area. An example of a source historical log audit table with rows every time a customer change:

 

SequenceId_log

EntryDate_log

Action_log

CustomerId

CustomerName

626

2000-05-08 10:12:34.4906240

Inserted

421

Marie Beaulieur

7503

2007-11-16

14:37:07.2353231

Updated

421

Marie Lesauvage

19473

2014-07-15

11:09:33.7629562

Updated

421

Marie Sainte

25003

2017-02-07

23:57:21.9876543

Deleted

421

Marie Sainte

 

Implemented as after-insert/update/delete triggers in source legacy system.

 

1.3. Enterprise Data Warehouse

In a data warehouse architecture and enviroment I will place data from the source legacy systems into a database called Enterprise Data Warehouse (EDW) which is based on Entity Relationship data modeling with super-sub entity, associative entity and with 80% normalized data. The EDW offers integrated, granular, historical and stable data that has not yet been modified for a concrete usage and can therefore be seen as neutral. It can keep historical data meaning all the changes to the data or only the days-end status e.g. End Of The Day for each data revision from Archive or Input data area. Let the design of the data model do a »helicopter perspective« when identification of entities e.g. salesperson or engineer will be stored in an Employee entity with a one-to-many to a Jobfunction entity or more abstraction to a Person entity where customers users can be stored too. Convert source data with timespan start date and end date to transaction row wise entity as transactional data that is a sequence of information exchange and can be financial, logistical or work-related, involving everything from a purchase order that become an invoice with multiple invoice line items, to shipping status, to employee hours worked, plan and activity records, for subscription period and to insurance costs and claims. The EDW will be the source to one or multiple Data Marts using the Dimensional modeling with denormalized data controlled by the ETL process or using other modeling depending of the use of data in the mart.

 

1.4. Reconciliation

After data capture, please remember to implement a Reconciliation Summary Report with the results from your different recon e.g. Uncategorized assets, Invalid country codes, Derivatives transactions with missing currency code.

Audit trail (in danish kontrolspor) becomes important for the credibility of a data ware­house. An example from a source legacy system that has a value 0.003589 and export it to a txt file where the value becomes 3.589e-3 and by a mistake in the ETL process the data warehouse saved and displayed the value as 3.589. When reconciliation is built-in the data model and the ETL process, this mistake would be reported and the programmer can fix the import and update his data profiling do­cu­men­ta­tion.

 

1.5. Schema

Dimensional modeling ends up in a star schema or constallation sche­ma (multi-star schema) with fact tables (analysis variable, measures, events) surrounded by dimension tables (context), where dimensions explain the facts. Di­mension and fact conformance is a must in a successfull data warehouse imple­men­tation to meets the requirements of legislation, accepted practices, prescribed rules and regulations, specified standards and terms of a contract.

 

Before I used the general word data mart for a database with tables of dimensions and facts, but there is a more narrow word Multidimensional database (MDB) that is the source database for an OnLine Analytical Processing (OLAP) application like a cube also known as a Multidimensional online analytical processing (MOLAP) application. To me, it is a principle for a cube that all dimensions and all measures can be combined freely else divide into multiple cubes.

 

1.6. Data quality

Some data quality skills and data cleansing examples:

  • Accuracy like is the age of a person is trusted and not like 134.
  • Validity like a date is within an acceptable range and not ten years wrong else data become invalid and should be rejected or corrected.
  • Correction like changing a wrong year of a date or casted to right data type.
  • Duplication like same customer has addresses spelled in different ways.
  • Consistency like a zipcode is right and has a cityname or a data mapping like DK for Denmark. Inconsistent value gives problem in any database and data warehouse.
  • Completeness to avoid data values is missing like a phonenumber or a date.
  • Conformity to make data from different source legacy systems conformed and approved values that take care of case-sensitive words through translate, map­ping or bridging rules to create one and only one truth.
  • For fact tables one truth depends of the use because a fact for Finance and a fact for Marketing may look like the same but their business requirements specification has small differences.

 

1.7. Big data

Some properties of big data:

  • Volume refers to the amount of data e.g. from GB over TB to PB as data at scale and transactions.
  • Velocity refers to the speed of change and data processing for the timeliness of data, data in motion from batch in the night, periodic loads e.g. three times a day, near real time with some delay and real time with almost no delay or streamning data with no delay as interactive.
  • Variety refers to data in many forms and the number of types of data from relational database, image, photo, audio, video, multimedia, sensor, web logs from social network data, smartphone and unstructered text.
  • Variability to increase in the range of values typical of a large data set and non-standard.
  • Value refers to data of many values which addresses the need for valuation of enterprise data e.g. statistical, events, correlations, hypothetical, leve­rage­able.
  • Veracity refers to data uncertainty due to data inconsistency and incom­pleteness by managing the reliability, trustworthiness, authenticity, origion, repitation, availability, accountability, quality and predictability of inherently imprecise data types.
  • Visibility refers to data in the open and being able to handle european General Data Protection Regulation (GDPR) and issues of privacy, security and provenance.
  • Visualization refers to the flexible viewing of data.
  • Viscosity, Validity, Venue, Vocabulary and Vagueness is other V-words.

 

A data lake can be used for massive quantities of unstructured data and big data with tools that can easily interface with them for analysis for business insights. Sometimes called Data Discovery Area as an end-user sandbox. A data lake uses ELT (extract, load, and then transform). A tool for a data lake can be Hadoop.

 

A relational database is characteristic by ACID (Atomic, Consistent, Isolated, Durable). This means that a transaction is either carried out completely or not at all (Atomic), that only valid data is added to the database (Consistent), that transactions never affect each other (Isolated), and that transactions are never lost (Durable).

 

A NoSQL = Not Only SQL database means it can use SQL type query language, but usually do not do so. NoSQL database often designed to run on clusters, made by open source and the database do not operate with a fixed schema structure but allow the addition of data without a pre-defined structure. A NoSQL database is cha­rac­te­ristic by BASE (Basic Availability, Soft state, Eventually consistent). An ACID system guarantees data consistency after each transaction; a BASE system guarantees data consistency within a reasonable period of time after each trans­action. In other words, there is data consistency in the system, just not im­me­dia­tely. This leads on to the Soft State principle. If the data is not consistent at all times, the system must take a temporary data state into account. The sum of both these principles means that data accessibility is given very high priority, even if coincident errors occur in the database system, operating system or hardware. If parts of the database do not work, other parts of the database take over, so that data can always be accessed.

 

2. Grain (granularity) of data warehouse

The grain is the level of detail of data in the table, both in dimension tables by the hie­rarchy and in fact tables by the definition of the measurement event and of in­terest, and the grain can later be expressed in terms of the dimensions. The lowest grain keep all relevant data from source legacy systems and is therefore the most flexible approach but also take most storage space and easy can cost high query per­formance. To improve query performances the grain can be lifted up to higher level whi­le data will be aggregated and summarized and therefore take less storage space. Data can also be divided such as current year data is in grain daily (dately), previous year in weekly and older data in monthly, because very detailed infor­mation is normally not relevant for analysis years back in time. Granularity of fact table can be divided into three types:

 

  • Transaction grain as finest level of detail with one row per transaction together with a transaction datetime like a entry date, post date, sales date or simply a created date, inserted time or registered date of the row.
  • Periodic grain with one row per time period or time span like a week or a month.
  • Accumulating/Aggregated grain as more summarized level like one row for the en­tire lifetime of an event or with a clear beginning and end.

 

Aggregation is the process of calculating summary data from detail base level table rows (records) and is a powerful tool for increasing query processing speed in data marts. For example a sale is a fact with analysis variable and measures like quantity sold and amount, dimensions like product, customer and date of purchase that bring a sale in a context. The grain of the sale is limit to a date (like December 23) and a time (like 4:30 pm) and therefore the fact is on Transaction grain. In case we drop the time, the measures would be called TotalQuantitySold and TotalAmount because they are the result of a summation of sales time to sale date and therefore the fact is on Periodic grain. Also if we decide to summarize the sales date to a weekly or montly level. In case we decide to grain the customers by aggregate them into segments and don’t keep names and adresses, then the fact becomes Ac­cu­mu­la­ting/Aggrega­ted grain. The product has a three level hierarchy of category name, brand name and product name, and therefore we can say that product has the highest level of detail.

Instead of summation of sales time or sale date and loose some important information of date of purchase, we can summarize data into two other fact tables for a weekly level for data from the last year and a monthly level for older data, because when we go back in time we do not need analyzes on a dai­ly or we­ek­ly level and by aggregation we save harddisk space and improve the performance of the query because fewer rows in month level need to be summarized to fetch the year level data.

The lowest level of aggregation or the highest level of de­tail is referred as the grain of the fact table.

 

3. Fact

A fact table contains columns of dimensions and columns of analysis variable and measures. A fact table can contain fact’s data on detail or aggregated level depends of the grain approach. All measure columns in a fact table should have the same grain like dately or monthly level. A fact table typically has two types of columns, foreign keys to dimension tables and measures that contain numeric facts. Every fact table has a primary key de­fined by a subset of the columns in the table, but normally a surrogate key i­den­tity column a unique sequence number is used instead. The ETL process has to secu­re the natural key, so fact rows are distinct. Fact tables in a di­men­sio­nal model express the many-to-many relationships between dimensions and is implemented as one-to-many relationships between dimension tables and fact tables.

 

3.1. Types of facts

Let us characterize the various facts into different types of facts or more exactly different ty­pes of the columns in a fact table. Conforming facts means making agree­ments on common business metrics such as key performance indicators (KPI) across separa­ted source legacy systems so that these numbers can be compared mathematically for calculating differences and ratios.

 

Additive fact

A fact table has numerical measures that can be summed up for all of the di­mensions in the fact table, so the measure columns data type is a number. A sales fact is a good example for additive fact with measures like Quantity sold and Amo­unt. In case of a transaction dataset to a fact table refer to a measure column which value is empty, null or nullable, use the default value 0 because this won't bother aggre­gation like summation. Each measure must have its metrics. If it is a monetary measure, it may have a currency field and if it is a unit measure it may have a field to explain the kind of units used like centimeters, litres, cubic metres etc. Fact can have a cal­culated measure or a derived measure based on existing measures and constants e.g. Profit or Surplus = Revenue – Costs.

 

Semi-Additive fact

A fact table has measures that can be summed up for some of the dimensions in the fact table and not for other dimensions. For example a daily balance measure can be summed up through the customers dimension but not through the time di­men­sion. Inventory levels cannot be summed across time periods.

 

Non-Additive fact

A fact table has measures that cannot be summed up for any of the dimensions in the fact table. For example a room temperature fact is non-additive and summing the temperature across dif­fe­rent times of the day produces a totally non-mea­ning­ful number. However, if we do an average of several temperatures during the day, we can produce the average temperature for the day, which is a meaningful number. Other example is a percentage and a ratio measure. A fact table that only contains column with transaction number such as order num­ber, invoice number or a voucher number that can’t be summing up. A order fact with measures like Unit pri­ce and Discount percentage where a Unit price for a single product ma­kes no sence to summarize, but the derived column Amount = Unit price x Quantity is to be summarized and become an additive column, called a calculated measure. Trend, Stock and Ranking can't be added and in general all calculations on one specific intersection of the dimension. Year-to-Date ytd measure can’t be summed up. Count of rows is normally used.

 

Factless fact

A fact table that contains no measures is called factless or measureless fact. For example a fact table which has only columns for employee, date, time and type, where type is like »work­start«, »work­stop« and »workstopofsickness« and there are no columns for measure. You can get the number of employees working over a period by a »select count(distinct EmployeeId)« or by a distinct row-count cal­cu­la­ted mea­sure in your OLAP cube. For a factless fact you will normally count the number of rows, row count or counting rows and call it »Number of <a name>«. Sometimes a factless fact has a value column called Count with only one value as 1 used in a data access tool to sum over and get the number of rows. Factless fact is for registration of event or assignment i.e. attendence take place in a school class with dimensions for student, class, room and professor. If we add a measure column for Attendence with 1 or 0 per date per student it is not a factless fact anymore. Factless fact can be used to represent a many-to-many relationship among dimensions.

 

Capture a relationship fact

To be a column in a dimension or to be its own dimension and used in a fact is a good question. Kimball’s financial services example starts with an Account di­men­sion including data of products and branches but he choose to remove these descriptive columns to form independent dimensions of Product and Branch and use them in a fact together with the Account. Therefore the fact capture a relationship among accounts, products and branches. Another example is that an account can belong to two customers and a customer can have several accounts. This many-to-many relationship can be expressed in a factless fact or in a bridge table, see later. A bank transaction is done by one customer from an account and it is natural to have a Customer dimension in the fact.

 

Transaction fact

A fact table that describes an event or operation that occurred at a point in time in a source legacy system e.g. an invoice line item, and the data row will never be chan­ged in the source. The row has a date e.g. a transaction date, an entry date or a post date and sometimes a time to represent the point in time with other lowest-level data.

Some data modeler do not like separate facts for each transaction type but build a single blended fact with a transaction type dimension and a mix of other di­men­sions can make N/A dimensions. I have seen a blended fact called FactEvent which I think is a poor and non-signing name of a fact table, and a date dimension gets a generalized name instead of multiple facts has names as order date, pur­chase date and receipt date.

 

Periodic snapshot fact

A fact table that describes the state of things in a particular instance of time, and usual­ly includes more semi-additive and non-additive measures. It is a table with frozen data, meaning a row will never be changed/modified/deleted (is unchanged) be­cau­se the row can have been used in a report like a monthly or annual report and later it is a must to be able to create the same raport with the exact same data. The periodic snapshot fact table will never been truncated or updated, therefore it is a true incre­men­tal insert load and the table has a column like a Month (yyyymm) for a monthly basis or a Year to fetch the wanted data as a month slice or a year slice. Measures can be a balance in account or inventory level of products in stock and so on.

 

Accumulating snapshot fact

A fact table that describes a process with milestones of multiple dates and values columns with different names which will be filled out gradually. Therefore over time the same fact table row will be revisited and updated multiple times where a default date value would be 0 for »hasn’t happened yet« or »be available later«. Each stage of the lifecycle has its own columns e.g. milestones of a hospitalization or steps of the manufacturing of a product. In a retail store a product has three movements as ordered, received and sold that would be three date dimension columns in an accumulating snapshot fact.

A fact table where a row is a summarize of measurement events occurring at predictable steps between the beginning and the end of a process. For example a source legacy system for current payments from customers where some pay seve­ral times over a month, and the first payment become a new row in fact table with date of payment in columns BeginDate and EndDate and the amount in Paid column. The next ETL process will do a summarize of payment per customer from the Begindate to current date or end-of-month date, and then update the fact row with same BeginDate with the new summarized payment and new EndDate, so a fact row will be revisited and updated multiple times.

 

Derived fact

A fact table that is created for performing a mathematical calculation and complex transformations on a fact table or on multiple fact tables.

 

Aggregate fact or Summarized fact

A derived fact table that is created to referred to as a pre-calculated fact with sum­ma­ri­zed aggregated measures at a higher level of one or more dimensions to reduce query time greatly and eliminate incorrect queries. For example a Month fact table that is a summation of rows of dates from another fact table. Year-to-Date ytd fact where month February is a summing up or roll up of January and February and so forth. Last-year-this-year fact with calculation of index compared to last year as a new column and easy to display in a report. Aggregate fact table is simple numeric roll ups of atomic fact table data built solely to accelerate query performance. Note that other dimensions may be rolled up to create less fact rows e.g. Address dimension becomes a Region dimension and Product dimension be­co­mes a Brand dimension and therefore the measures can be sum­ma­ri­zed to less fact rows for better query performance.

 

Consolidated fact

A fact table used to combine facts from multiple source legacy systems and busi­ness processes toge­ther into a single consolidated fact table if they can be expressed at the same grain. I.e. sales actuals can be consolidated with sales forecasts in a single fact table to make the task of analyzing actuals versus fore­casts simple and fast.

 

Timespan fact

A fact table used for a source legacy system that is regularly updatable meaning that the source change and overwrite its values. To capture a timespan when the fact row was effective, the fact table will act as SCD type 2 dimension with a ValidFrom and ValidTo columns to keep historical data and to represents the span of time when the fact row was the »current truth«. It is called Slowly Changing Facts. See more in section 6.4.

 

Counterpart fact and Transactional fact

A fact table used for Slowly Changing Facts because the source legacy system is changing fact value without keeping the old value as a historical transactions. See more in section 6.4.

 

Column wise fact and Row wise fact

A column wise fact table is usefull to be columns in a paper report e.g.

   Revenue Jan, Revenue Feb, Cost Jan, Cost Feb, Sales Jan, Sales Feb.

For a cube a row wise is much better because it gives good dimensions e.g.

   Period, Entry, Amount.

Therefore a data warehouse needs to convert from columns to rows or vice versa.

 

Conformed fact

When several data marts is using fact data with same name of fact tables and name of columns for measures and they have compatible calculation methods and units of measure and support additivity across business processes. If a measure e.g. Revenue is used in multiple fact tables with different calculations and meanings it is best to use different column names because theses facts are not conformed.

 

Exploded fact

A fact table contents huge number of rows where a period e.g. from a »date of employ­ment« to a »termination date« as columns in one row, will be turned around to many rows with one row per day of the period, or per week or per month depends of the wanted grain of the period. When an employee has 10 year anniversary it will make more than 3650 rows on day grain, and if the employee dimension keep hi­story of different names, departments and job functions etc. for each staff, then the fact rows will have different key references to the dimension. Another grain would be 15 minute grain which gives 96 rows per day for a windturbine power pro­duc­tion. When the exploded fact is a source for a olap cube it can sometimes be imple­men­ted as a view in the database, and when it is for ad hoc reporting it will be used several times per day then it must be a materialized view stored in a table.

 

3.2. Other fact classifications

Transaction has one row per transaction when they occur together with a datetime.

Periodic has one row for a group of transactions made over a period of time through summation like from daily grain to monthly grain so the Date dimension is re­pre­sen­ted by the month level with the first day of the each month. Notice that certain dimensions are not defined when com­pared to a transaction fact such as dimension TransactionType.

Accumulating/Aggregated has one row for the entire lifetime of an event and the­re­­fore constantly updated over time.  For example an application for a bank loan until it is accepted or rejected or a customer or working relationship. These fact tables are typically used for short-lived processes and not constant event-based processes, such as bank transactions.

 

Mostly a fact table describes what has happened over a period of time and is the­re­fo­re an additive or cumulative facts. An example of a status column in a fact table that receive data from a school system where a student follow a course and later finish it, but sometimes a student skip the course and are delete in the system. Before reload the fact it can be a good idea to have a CourseStatus column with values like: Active, Completed or Dropped.

 

4. Dimension

A dimension table containing business element contexts and the columns contain element de­scrip­tions and a dimension is referenced by multiple fact tables so the conta­ining mea­sure­ments make sense.

 

4.1. Purpose of a dimension

Some purposes as I seen it:

  • Slice and dice or slicing and dicing where the dimension value (member) is selected and become a filter, a zoom or a search criteria to do a filtering of the fact measure data and analysis variable after the wish of the user.
  • Dimensions are placed in the preposition and form rows and as columns and form a cross tabulation or pivot for presentation and reporting of analysis variable or measure value divided by dimension values.
  • Drill-down for presentation of dimension values in gradually greater detailing through a hierarchy or a group that is grouping values in intervals.
  • Drill-up or roll up views dimension value at higher aggregation level and is summing up the fact measure.
  • Drill-through shows the underlying data from the source legacy system.
  • Drill-across ties data marts and facts together through conformed dimension and different fact measures can be compiled.
  • Ranking or Sorting presents dimension values according to an analysis va­ria­ble, e.g. customer segments in descending order after the sale.
  • Top or bottom for presentation, e.g. top 5 products or 10 poorest customers on sale.
  • Contains relevant data columns for reporting, analysis and self-service BI.

 

The dimension values can be placed in a hi­e­rar­chy like a Location with levels CountryRegionCity and in a group like a Age with intervals Child (0-12), Teeanage (13-19), Adult working (20-66), Senior citizen (67-130). A dimension normally contains one or multiple hierarchies and/or groups to fulfill requirements from the u­sers. A dimension can of course be non-hierarchical and non-grouping.

 

Different dimensionality covers the issue that not all combination of multiple dimension values are allowed in a fact and the data warehouse needs to make sure of the data quality.

 

4.2. Dimension keys

A dimension table has mininum three types of co­lumns:

Primary key is a surrogate key identity column a unique sequence number to remove dependence from the source legacy system and for using in fact table foreign key. It can be called Entity key EK because it represent an entity from source or Surrogate key SK but for me »surrogate« is a property not a name of a column. Primary key must not be data-bearing (data bærende in danish), it must be mea­ning­less.

Business key is the primary key (or operational key) of the source legacy system, e.g. Id as a surrogate sequence number, a No (number) or a Code that is unique. Often the business key is a mea­ning­less value.

Natural key is other candidate key of the source legacy system based on data in the real world, like a Code or an unique Name. Natural key has an embedded mea­ning but they don’t need to be in the source legacy system because several data will never be unique.

Textual data is representing the dimension value context description and is saved in columns of the dimension table and will be shown to the users as descriptive attributes to explain fact data.

 

In a Customer dimension table we will have columns from source legacy sy­stem like Cu­sto­mer­Id, Customer­Num­ber and CustomerName together with Shipping­Address and Zipcode, Regioncode, Country, Age, Gender and what about the Bil­ling­Address and so on. Cu­sto­mer­Id is the business key and the Customer dimension primary key would be named e.g. Customer_key, CustomerId_dwh, Customer­EntityKey or EK or SK for surrogate key. »A beloved child has many names.«

 

Difference source legacy systems have a natural key for a social security number per person but the business keys is an individual surrogate sequence number, the­re­fore we can’t use them to interconnector (join, drill-across) the systems data instead we must use the natural keys. The value of a natural key can change over time e.g. a person obtains witness protection and gets a new social security num­ber and the business keys remains, then it is up to the ETL process to make a solid map­ping.

 

4.3. Changing dimensions

Dimension values will normally be changed over time such as a customer or pro­duct change the name or a hierarchical structure will be reorganized. The changes can be places into two kinds of classifications and afterwards we will be looking into some techniques to handle and tracking changes and to capture its history and preserve the life cycle of source data also called Change Data Capture CDC.

 

Slowly Changing Dimensions SCD

Columns of a dimension that would undergo changes over time. It depends on the business requirement whether particular column history of changes should be pre­ser­ved in the data warehouse or data mart.

 

Rapidly Changing Dimensions RCD

A dimension column that changes frequently. If you do need to track the changes, using a standard Slowly Changing Dimensions technique can result in a huge inflation of the size of the dimension. One solution is to move the column to its own di­men­sion with a separate foreign key in the fact table. Rapidly changing data usu­al­ly indicate the presence of a business process that should be tracked as a se­pa­ra­te di­men­sion in a separate historical data table.

 

Techniques or methods to handle dimension values that is changing over time from the source legacy systems, called Ralph Kimball’s eight types or approaches:

 

Type 0: Original value, where the dimension value never change (method is pas­sive) meaning keeping the original value from the source legacy system, and when the value is changed in source legacy system, we don’t change the value in the dimension. »Retain original«.

Type 1: Current value, where the old dimension value will be changed and for­got­ten when value is changed in source legacy system. The history of data values is lost forever. The actual, active, newest or latest of the value or most recent in­di­ca­tor. A fact table refers to a dimension value most recent, as-is. »Current by over­write«. Section 6.2 will show an example of type 1.

Type 2: Keep all values, where new dimension value is inserted into a new row to have an unlimited history of dimension values over time marked by Effective date and Expiration date (Active date, Expired date, Expiry date) (or Start­Date and StopDate or BeginDate and EndDate or ValidFrom and ValidTo), a pair of data type »date« or »datetime« that represents the span of time when a value was the »current truth«. A fact table refers to a dimension value in effect when fact data occurred, as-was, often by a date column in fact table based on source data or by a current load insert date when the fact data was entered into the fact table. »Keep history in rows«. The value of a business key will be repeated every time the tex­tual data is changing, therefore the primary key is a surrogate key identity co­lumn a unique sequence number. A view upon the dimension will provide the cur­rent va­lues. A view upon the fact will provide the current keys to join to dimension view. This is the technique for Slowly Changing Dimension. Section 6.2 will show an example of type 2.

Type 3: Keep the last value, where the previous dimension value is stored in a Previous column (or Historical column) and current dimension value stored in a Current column. »Keep history in column«. This is the technique for Slowly Chan­ging Dimension.

Type 4: Fast changing value in many dimension value columns are split into one or more separate Mini Dimensions. »Keep history in tables«. This is the technique for Rapidly Changing Dimension to store all historical changes in separate historical da­ta tables.

Type 5: Builds on the type 4 Mini Dimension by embedding a current profile mini dimension key in the base dimension that’s overwritten as a type 1 Current value column. Therefore 4 + 1 = 5 type. »Sub class dimension«.

Type 6:  Some columns follow type 2 with a key column and maybe other co­lumns fol­low type 1. »Hybrid«. Can also have column of type 3, therefore 3 + 2 + 1 = 6 type.

Type 7: All rows follow type 2 to keep track of historical values with a key column and an extra key column called a durable key follow type 1 for the current value. The durable key is an integer re­pre­sen­tation of the business key. The fact table contains dual foreign keys for a given dimension (its key and its durable key) to show the historical value of the dimension at the time the fact data was created, born or occurred, and to show the current value of the dimension. A view upon the dimension will provide the current values with the durable key to join to the fact durable key. »Dual Type 1 and Type 2 Dimensions«. Section 6.2 and 6.3 will show exam­ples of type 7.

 

In a dimension table the columns can be a mix of type 1 and type 2 e.g. a Customer dimen­sion where columns for customer name, street name, house or apartment number is type 1 because we only need the recent value for shipment, and columns for postal code (zip code) and city is type 2 because we like to tracking these changes and keep data for the city where a customer was living in when purchase a product. A »sales in cities« report for the last ten years will use the right city of the customer at the time the purchase occurred.

 

4.4. Types of dimensions

Let us characterize the various dimensions into different types of dimensions.

 

Conformed dimension or Shared dimension or Common dimension

A conformed dimension has the same meaning to every fact in multiple data marts and measures will be categorized and described in the same way and ensuring consistent reporting across the data warehouse. With a conformed dimension we can drill across from fact to fact and analyze common columns and values. Se­pe­ra­te fact tables can be used together with the shared, common and conformed dimensions. Conforming of several source legacy system data is part of the in­te­gra­tion to achieve a conformed dimension where data is integrated of different mea­nings and different columns must be compared against each other, rules must be set, and data must be cleansed to create a single version of the entity. Conformed dimensions will unite and integrate data values among different source legacy systems so it is easy to search across different types of data and sync them in common reports. Shared di­men­sion is utilized in multiple fact tables in a data mart or across multiple data marts. Di­men­sion values comes from either the source legacy systems or is built by business rules in Usage supporting database. Non-conformed dimension can only be used within one fact. It is part of the ETL process to do conforming by merge, united and consolidating different source legacy sy­stem data across the enterprise for making a conformed dimension e.g. a Cu­sto­mer dimension from different business areas  as order, sale, invoice, delivery and sup­port service (for B2B and B2C) with both different customers and same customers and with different business key values and with different addresses like a shipping address and a billing address. Sometimes data from a conformed dimen­sion is send back to the source legacy systems as master data to be reusable in the organization.

The dimension values can be placed in a hi­e­rar­chy like a Location with three levels CountryRegionCity. A dimension can have several separate and independent hierar­chies with different numbers of levels.

The dimension values can be placed in a group that is grouping values in intervals like person ages in custom buckets like a Age group column with intervals: Child (0-9), Tween (10-12), Teeanage (13-19), Young adult (20-29), Adult (30-66), Senior citizen (67-130).

A dimension normally contains one or multiple hierarchies and/or groups to fulfill requirements from the users. A dimension can of course be non-hierarchical and non-grouping.

 

Date dimension or Calendar dimension

Very common dimension with hierarchies such as

YearHalf yearQuarterMonthDate (five levels) or

YearWeekDate (three levels) because a week does not always belong to one month. The calendar date dimension has a granularity of a single day. I like to use an integer value as surrogate key identity column in format yyyymmdd e.g. 20131224 for Christ­mas day, therefore the fact table will contain useful information that can be used in a query like

»between 20131201 and 20131231« for month of December 2013.

When a fact date is connected to the Date dimension it is easy to make a re­port based on month, quarter or yearly level or a search filter cri­teria as Q3 2013.

 

When a surrogate integer value is used instead of a date stamp it allows us to have values to handle these cases:

»Missing« (0) the date is not present or hasn’t happened yet or date to be de­ter­mi­ned but is expected to be available later and fact table will be updated thereby.

»Not available« (-1) the source legacy system did not provide a date value and will not do it later.

»Not applicable« (-2) the dimension is not relevant for the fact row (N/A, N.A.).

»Bad« or »Dirty« (-3) the source legacy system provide bad date e.g. year of birth as 2099 or February 29, 2017.

»Unknown« is used for an inferred member in a fact table without a member value in the dimension. Hopefully all dates in a fact table will already exists as values in the date dimension. Please read more about it in section 4.5.

 

A fact table has often at least one column that represent a date e.g. an entry date, order data, invoice date, shipping date. When an event is happening it has normally a date or multiple dates like an injury with an InjuryDate, a ReceivedDate at insurance company, a RulingDate, a TreatmentDate, a BillingDate and a PaymentDate. Date dimension is often a role-playing dimension and therefore the data mart contains multiple views upon the date dimension so each view can join to each date column in the fact table and each view has a good name like the columns in the fact table.

 

Time dimension or Time-of-day dimension

A normally hierarchy HourMinuteSecond or by an aggregation hierarchy that roll up of time periods into more summarized groupings like this:

Morning (6 am to 8 am)

Rush hour (8 am to 11.30 am and 4 pm to 6 pm)

Lunch hour (11.30 am to 1 pm)

Afternoon hour (1 pm to 4 pm)

Dinner hour (6 pm to 8 pm)

Evening hour (8 pm to 11 pm)

Night hour (11 pm to 6 am)

I like to use an integer value as surrogate key identity column in format hhmmss e.g. 63000 for 6.30:00 am and 202530 for 8.25:30 pm because 8 pm is also called 20 o’clock in the evening.

 

Regular dimension

All dimension members or values (or branches in the hierarchy) have the same number of levels which makes the dimension symmetrical or balanced such as the Date dimension or fixed-depth hierarchy CountryRegionCity where the three levels is in separate columns. Se­veral columns in the dimension table is not at third normal form (3NF), therefore the dimension table contains re­dun­dant data or duplicate data by nature. A re­gu­lar dimension has a flattened denormalized struc­ture. A Pro­duct dimension table can have columns like ProductId, Code, Name and other descriptive fields, a Category because products are divided into categories and each category has a Target group. When a category belongs to multiple pro­ducts, the target group will be repeated, meaning it does not satisfy third normal form (3NF), but it is okay for a regular dimension.

 

Example of a Product dimension with hi­e­rar­chy Target groupCategoryProduct

 

Product_key

Code

Name

Category

Target group

5831

E-973

EVGA GTX Titan

Graphic card

Gamer

5832

G-108

GeForce GTX 1080

Graphic card

Gamer

5833

R-929

Radeon R9 290

Graphic card

Gamer

7092

B-009

Besteker Q9

Karaoke mic

Singer

7093

C-008

CHUWI K8

Karaoke mic

Singer

9250

U-670

Ultra boost

Running shoe

Sport practitioner

9463

T-001

Trek Madone 9.9

Racing bicycle

Sport practitioner

 

There is three levels in the dimen­sion hi­e­rar­chy and it is balanced meaning that each Product has a Category and each Category has a Target group, so the dimen­­sion hi­e­rar­chy maximum dimensionality is 3 (level of dimensionality).

 

For the Product dimension the product is the lowest level of granularity, and there is two many-to-one relationships because many products roll up to a single category and many categories roll up to a single target group.

 

Ragged dimension

A ragged dimension has leaf members (the last level of a hierarchy) that appears at different levels of the hierarchy and therefore contains branches with varying depths and number of levels. Eu­ro­peDen­markCopen­hagen with three levels,

North AmericaUnited StatesCali­for­niaSacra­mento with four levels represent

continentcountrystatecapital. To keep that hierarchy structure for a fixed ba­lan­ced regular dimension I have made a dummy level not applicable state for Dk: Eu­ro­peDen­markN/ACopen­hagen.

A ragged dimension is implement as a Parent-child structure or with a bridge.

 

Parent-child dimension

Used to model flexible hierarchical structure where some dimension values have different levels of hierarchies called unbalanced or variable-depth hierarchy. Every value in the dimension have a related parent (mother) value, except the top value. The hierarchy is a­sym­me­tri­cal or unbalanced because values are placed in dif­fe­rent levels within the same hierarchy. For example an Employee dimension where the parent is the ma­na­ger and the children is the employees under the manager, and some employees are both a manager and have another manager above, and the chain of command can be different from department to department. Another example is an Organization dimension where some departments have sub-de­part­ments and some teams have sub-teams, but there are also teams that don’t have sub-teams. This is the stron­gest side of Parent-child dimension to modeling.

 

Snowflake dimension

Dimensional model dimensions is comply with second normal form (2NF).

a) Splitting columns of a dimension table into smaller dimension tables with one-to-many relationships so data values fulfill and comply with 3NF and BCNF to avoid re­dun­­dant data and denormalized structure.

b) Splitting a dimension hierarchy into two or more dimension tables is called »snow­fla­ke a hierarchy«. For example a Customer dimension with the hi­e­rar­chy:

CountryRegionCity will be split into three dimension tables so only column City remains in the Customer di­men­sion table that is connected to the Sales fact table, and two Snowflake dimen­sion tables for Region and for Country with one-to-many from Country to Region and one-to-many from Region to Customer. Region and Country can be reused in other dimensions for Supplier and Store or in a FactSales to quick divide in regions and countries. Of course depending of business re­qui­re­ments specification.

c) Splitting a dimension with columns from different source legacy systems or when some columns will be user type-in from an application to enrich data and to avoid re­dun­­dant data. See an example in section 6.1.

d) A Product dimension with a Category hierarchy is used in a Sales fact and Inven­tory fact. For forecasting (budgeting) the data is generated at Category level. Kimball will not do snowflaking of Product dimension instead he roll ups to Ca­te­go­ry dimension as a strict subset of Product that the ETL process must take care of.

e) Splitting dimensions and move common columns to a general dimension is called an Outrigger dimension. For e­xam­ple an Address dimension with street name, house or apartment number, postal code, city, county, area, region, country, gps coor­di­na­tes and so forth to be used in other dimensions e.g. a Customer dimension with a shipping address and a billing address, a Building dimension with location address and an Employee di­men­sion with home address. The Address dimension contains one row per unique address. A Sales fact can have a ShippingAddress_key and a BillingAddress_key as role-play­ing dimensions. Or a factless fact table with Customer_key, Ship­ping­Address_key, BillingAddress_key and effective and ex­pi­ra­tion dates for repor­ting track addresses of a customer. See more later.

f) An Shrunken dimension is a kind of snowflaking, see later.

g) Splitting a dimension with rapidly changing columns is not snowflaking, see Mini.

h) Kimball’s financial services example starts with an Account dimension including data of products and branches but he choose to remove these descriptive columns to form independent dimensions of Product and Branch and not snowflake the Ac­count instead add them to the fact because that’s the way business users think of them too. The fact will capture the relationship among data en­ti­ties.

Some data modellers do not like Snowflake dimension be­cau­se of the query per­for­man­ce with more tables in the join. I don’t use the terms snowflake schema and starflake schema because for me snowflake belongs to a dimension and sometimes it is great to have a denormalized structure and other times it is good to think of the above points. Most times a data mart will be a constallation schema (multi-star schema) where some dimensions is shared among different facts.

Now and then a data warehouse architecture has an extra layer after the data mart that is called presentation area where the ETL process or a view has joined and merged snowflaked di­men­sions together to only one dimension with all the columns with a lot of data redundancy, and that is fine sin­ce this layer will be refilled in every ETL process and it is easier for the users to do their query and for the tool to load data into its data model. Can use a materialized view that stored data into a table. The layer is also called data consumption layer or data delivery layer for reporting, analysis and self-service BI.

 

Outrigger dimension or Reference dimension

When many columns belong logically together in a cluster or group it is fine to do a snowflaking to avoid a repeating large set of data and therefore making a di­men­sion smaller and stable. Sometimes a canoe or a sailboat is using a rig to achieve balance because they are very narrow and a cluster of columns is placed in a Out­rig­ger dimension or a reference dimension because it’s primary key will be a foreign key in the main dimension, but there is no reference found in any fact table. For example a Product dimension has a column called OfferDate that represent the date when the product will be available for the customers, and from that date the product can appear in the Sales fact table. The OfferDate column is a foreign key to a Date dimension that become Outrigger di­men­sion because Date dimension has many columns about dates, weeks, months, years and maybe fiscal columns too. Another example is demographic data for each country which is providing with 50 different columns. When we using outrigger dimensions we let each dimension has its own core columns.

Another example is from a bank with two kind of customers for Person and Com­pa­ny with common data as name and address and with specific data where a Person has social security number, gender and marital status and a Company has VAT iden­tifi­ca­tion number, industry code and turnover amount. A Customer di­men­sion handle the connections to the fact tables and become a hub, an anchor or a party. Every time the bank gets a new customer, it will be set up in Customer dimension and the surrogate key value will be reused in either Person outrigger dimension or in Com­pany outrigger dimension where both of them have a one-to-one rela­tion­ship to the Customer dimension.

 

Shrunken dimension

A Shrunken dimension is a subset of another dimension columns that apply to a higher level of summary.

a) The Month dimension is a shrunken dimension of the Date di­men­sion. The Month dimension would be connected to a fore­cast fact table whose grain is at the monthly level, while Date dimension is connected to the realized fact table.

b) Shrunken roll up dimensions are required when constructing aggregate fact table. When a Sales fact has a daily grain the number of rows can become very large over time, therefore an aggregate fact summarized to monthly level will have less rows. Since the aggregate fact don’t need detailed customer information, the Customer dimension can make new shrunken dimensions for Region out of address, Gender and Age interval, and the summarized fact data become even less rows.

c) An Order fact table includes a foreign key for Product dimension, but the target fact table wish only to include a foreign key for Category dimension, which is in the Product dimension with less granular. The Product dimension can be snowflaked to a separate table for Category dimension, or there can be a map table between the two tables of Product and Category so they are not directly related.

d) Sometimes users want few dimension values e.g. Red, Yellow and Green and they want Pink to become Red and Orange to become Yellow and so forth and the rest of the colours gets a residual value called Others. I will make a Colour di­men­sion for the colours from the source data and I will make an extra Colour­Group dimension for the four colours Red, Yellow, Green and Others. I will make a map table that will translate the colours like Red to Red, Pink to Red, Yellow to Yellow and Orange to Yellow and the rest of the colours to Others. In the loading to the fact table I will let the colours go through the map and fetch the ColourGroup di­men­sion to the fact table to obtain good performance for various statistics for the users.

 

Derived dimension

Like a Month dimension that is derived from a Calendar dimension or we can say that Calendar has been reduced to Month, Year and Week with the start date of the week together with a week number and which year the week belongs to. A derived dimension can also be created by aggregating two existing dimensions.

In a hospital we can from a Patient dimension and an Employee dimension derive a Person dimension. A person can over time be both an employee and a patient or at the same time when the employee become sick and will be hospitalized.

Fact data can derive dimension data and it is called a degenerate dimension.

 

Mini dimension

For Rapidly Changing Dimensions and used for managing high frequency and low cardinality changes in a dimension of fast changing columns they are typically pla­ced in a mini dimension with its own surrogate key identity column which is included the fact table. A dimension table will be split into two tables, one with type 0 or 1 columns and the other with type 2 or 4 columns. For example customer data with columns as Name, Address and CountryRegionCity is placed in a Customer dimension table, and the fast changing columns BodyWeightAt­Pur­chase­Time and MonthlyIncome interval e.g. $ 0-10000, 10000-25000, 25000-50000, 50000-99999 is placed in a mini di­men­sion table called Customer­Body­Weight­Income with its own surrogate key identity column. The sales fact table will have two columns to provide data for a customer, one key for Customer dimension and another key for Cu­sto­mer­­Body­­Weight­­Income dimension. Sometimes it is necessary to have two or more mini dimensions if the columns is changing rapidly at different times. Normally there is no hierarchy in a mini dimension.

 

Bridge dimension

The bridge is to connect or map data that have a many-to-many relationship between a fact and a dimension or between a dimension and a dimension to take care of multivalued attribute at the conceptual level, and break it down at the logical level to a bridge dimension table with two one-to-many relationships and a com­po­si­te primary key from the implicated data. Instead of the word Bridge table a term Helper table could be used. Peter Chen calls it an associative entity. A bridge table can also be used for ragged hierarchies.

 

Multivalued dimension or Many-valued dimension

a) To handle when one fact row have two or more dimension values from same di­men­sion. For example a Sales fact can have up to four different sales staff em­ploy­ees and a sales staff has many sales. Therefore we say there is a many-to-many relationship be­twe­en Sales fact and ­Em­ploy­ee dimension, and sales staff employee becomes multivalued in the Sales fact. It can be implemented by an extra table called SalesEm­ployee­Bridge that contains the Id of a fact row and the Em­ployee­_key from the Employee dimension, or the fact table will get a dimension key co­lumn for a SalesEmployeeGroup di­men­sion meaning a group of sales staff is con­nec­ted to one fact row; and since there is a many-to-many relationship between a SalesEmployeeGroup and a Employee dimension, a SalesEmployee­GroupBridge ta­ble will express that by com­bi­ning the keys from SalesEmployeeGroup and Em­ployee.

b) When buying a paint mixture the different colors are mixed with a ratio or weight (sum up to 100%) the amount of paint. One sales fact row contains many colors and one color is included in many paint mixtures. Color become multivalued and a bridge gets a weight value to tell how much of that color is used.

c) To handle when one dimension row has two or more dimension values from a­no­ther di­men­sion. For example an employee has a group of skills and one skill can belong to several employees. Therefore we say there is a many-to-many re­la­tion­ship be­twe­en Employee dimension and Skill dimension, and skills of an employee becomes multivalued in the Employee dimension. It can be implemented by an extra table called EmployeeSkillGroupBridge that has a com­po­si­te primary key of Skill­Group_key and Skill_key, and SkillGroup_key is a foreign key in Employee di­men­sion and Skill_key is a foreign key in Skill dimension, so the many-to-many re­la­tion­ship comes two one-to-many relationships. The data ex­pe­rien­ce level would be placed in the EmployeeSkillGroupBridge. Sometimes we crea­te a fact table e.g. EmployeeSkillFact, but for me a skill is a description and a cha­rac­te­ri­stics of an em­ploy­ee in a company and facts would be a Sales fact or a Pro­duc­tion fact. In a School mart I would place the students' courses in a fact table because it is a result of study and passed an exam. Another example is a t-shirt can have up to three sizes »small«, »medium« and »large« and they can become three columns in the T-shirt dimension, or to make a Size dimension that has a many-to-many relationship to T-shirt dimension and the relationship become a T-shirt­Size­Bridge with Quan­tity­InStock. Another example is a bank account can two bank customers like wife and husband, and of course each bank customer can have several accounts like budget, saving and pension. Therefore we say there is a many-to-many re­la­tion­ship be­twe­en Customer dimension and Account dimension. We create a Bank­Account fact ta­ble that will refer to the Account dimension, and the Account dimension refer to an AccountCustomerBridge table that again refer to the Customer dimension, so the BankAccount fact table will not refer directly to the Customer dimension. The Ac­count­Custo­merBridge table contains two columns Account_key and Cu­sto­mer­_key as a composite primary key so an account can have several customers.

 

Role playing dimension or Repeated dimension

A role-playing dimension is repeated two or several times in same fact i.e. a Date dimension which key column is repeated in three foreign key columns in a fact table for three roles labeled SaleDate, ShipDate and DeliveryDate. Here is the Date di­men­sion taking multiple roles and a user will get three dimensions with its own na­me and its own column label name made by using three views based on Date dimension table. Another example is a boolean dimension with key values 1/True and 0/False and in different views for several role-playing statuses the two values is translated to good texts as »Yes« and »No«, »In stock« and »Delivery made«, or »Available« and »Utilized« for a Utilization status. A City dimension can be repeated in multiple roles in a fact table of persons like these columns: BirthplaceCity, ResidensCity, WorkingplaceCity and DeathCity.

 

Junk dimension or Garbage dimension or Abstract dimension

A single table with a combination of different and unrelated columns to avoid ha­ving a large number of foreign keys in the fact table and therefore have decreased the number of dimensions in the fact table. Kimball recommand up to 25 di­men­sions to one fact. The content in the junk dimension table is the combination of all possible values of the individual columns called the cartesian product.

For examples of three different values that can be joined into one dimension with

3 x 2 x 2 = 12 values or 12 rows in the Junk dimension table such as:

Customer feedback: Good, Bad or None.

Payment type: Cash or Credit card.

Bag type: Plastic or Paper.

Does not need to be the cartesian product of all the attributes possible values, but should only contain the combination of values that actually occur in the source data.

 

Degenerate dimension

Degenerate dimension values exist in the fact table, but they are not foreign keys, and they do not join to a real dimension table. When the dimension value is stored as part of fact table, and is not in a separate dimension table, it is typically used for lo­west grain or high cardinality dimensions such as voucher number, transaction num­ber, order number, invoice number or ticket number. These are essentially dimension key for which there are no other columns, so a degenerate dimension is a dimension without columns or hierarchy. For example the OrderNumber column can be in the Order fact table with several rows using the same order number, because one order can contain several products. Therefore the OrderNumber column is important to group together all the products in one order. Later for searching for an order number in a OLAP cube, a Order number dimension is very usefull, but it is not a dimension table, it is generated by the Order fact table.

Degenerate dimension is also used as an im­ple­men­ted Bridge dimension table in making a Multivalued dimension. In a data mart these are often used as the result of a drill through query to analyze the source of an aggregated number in a report. You can use these values to trace back to transactions in the OLTP system.

Normally a degenerate dimension is not a table in a da­ta­base, it is a view with distinct values based on the fact table.

 

Dimensionalised dimension

Dimensionalised dimension is a replacement of Degenerate dimension where the view become a materialized view meaning it become a table in the data mart and where the text column will be transformed to an integer key, like this:

 

SELECT QuantityPerUnit_key = CONVERT(BIGINT, HASHBYTES('MD5', t.QuantityPerUnit)),

            t.QuantityPerUnit

    INTO DimQuantityPerUnit

FROM (SELECT DISTINCT QuantityPerUnit

           FROM Products WHERE QuantityPerUnit IS NOT NULL) t

 

Static dimension or Constant dimension

Static dimensions are not extracted from the source legacy system, but are created within the context of the data warehouse or data mart. A static dimension can be loaded manually for example with Status codes or it can be generated by a pro­ce­dure, such as a Date dimension. The opposite would be called Dynamic di­men­sion.

 

Aggregate dimension

Dimensions that represent data at different levels of granularity to give higher performance. Can also refer to hierarchies inside a dimension with a higher grain.

 

Heterogeneous dimension

Several different kinds of entry with different columns for each fact (like sub clas­ses). For example heterogeneous products have separate unique columns and it is therefore not possible to make a single product table to handle these he­te­ro­ge­ne­ous products.

 

Fact dimension

Used to identify different facts that is populated in the same measure column in a fact table because the fact rows represent different entry typies. An entry type fact dimension describes what the fact row represents and how measures must be understand and used. The alternative is to have multiple measure columns for each entry type in the fact table where only one column has a value for each row.

 

Time machine dimension

A combination of two dimensions for Entry date (or event date) and for Year and where fact data rows is based on either »counterpart« as in a financial accounting or »transactions« as in a financial transactions. Section 6.4 will show an example.

 

Monster dimension

A very large dimension that has a huge number of rows or many columns. For a real e­state agent, I implemented a 132-columns dimension through a merge of five source legacy systems. The column names was made together with the users. The created dimension table got the column names in an alphabetical order so it is easy to find a specific column.

 

Supernova dimension

Dimensional attributes are allowed to become complex objects rather than simple text like unstructured text, gps tracking, graphic images and in time series and in NoSQL bases like Hadoop and MongoDB, and become much more malleable and extensible from one analysis to another. Extensible design in software engineering is to accept that not everything can be designed in advance and extensibility is a soft­ware design principle defined as a system’s ability to have new functionality extended.

 

Audit dimension or Data quality dimension

A description of each fact table row would be »Normal value«, »Out-of-bounds value«, »Unlikely value«, »Verified value«, »Unverified value« and »Uncertain value«.

An audit dimension can also have data for name and version of source legacy sy­stem, name of data table in source, time of extract from source, time of insert into the fact table etc.

 

4.5. Inferred members or Inferred dimensions

A dimension has a member value of »Unknown«, »Missing«, »N/A«, »-« etc. to handle source data that is going to be loaded into a fact table:

 

  • The fact business key has no value, it is null or it is an empty string.

Approach: Handling a null/empty business key as a missing member be­cau­se a row in the fact table for column of business key is not registered.

 

  • The fact business key value not found as a member of the dimension.

Approach: »Early arriving fact« for handling of orphaned data where the fact data has an unknown mem­ber, meaning the fact value is an orphan child because there is no parent value in the cor­re­spon­ding dimension table, the fact value does not exist in the dimension.

 

In a relational database it is called a referential integrity constraint violation in a table when a foreign key contains a value that does not exists as a primary key in a different (or the same) table. There is a no referred member and there is a need to have an inferred member. A forthcoming fact row has a member that will infer a new dimension member, therefore it is called inferred member of the dimension and it is to im­pro­ve data quality and audit trail/control track for re­con­ci­lia­tion in the data warehouse.

 

Handling a null/empty business key as a missing member

When a dataset is transformed to a fact table, there can be a business key column which value is empty or null, meaning it does not yet exist for the fact data. To keep all the fact data rows in the fact table, the related dimension table is already born with a »Missing« value (an inferred member) with surrogate key identity value 0, which can be used as a default value in the fact table foreign key column to the dimension table primary key column. Later the fact table with a 0 value can be up­da­ted with a real business key value that either exists in dimension table or will be inserted there first and therefore has a real surrogate key identity that the fact data row can refer to. Sometimes I have seen a dimension with an inferred mem­ber value of -1 for »Unknown«, but I prefer using value 0 for »Missing« and using »Unknown« to handle the situation I will describe below, because I divide infer­red members in two situations as the points shown above.

 

Early arriving fact as an unknown member

When a dataset is transformed to a fact table, there can be a business key column which value has not yet been received to the related dimension table and therefore does not yet exist. To keep all the fact data rows in the fact table, the related dimen­sion table will first have to insert a new business key value with an »Unknown« value (an inferred member) which later will be updated in the di­men­sion with the correct text value then it is known. The »Unknown« value gets the next surrogate key identity as an unique sequence number and will be used in fact table like any other dimension member value. A dimension table can at the same time have se­veral »Unknown« member values with their own business key, sur­ro­gate key identity and the text value can include the value of the business key like »Unknown 886«, »Unknown 887«, »Unknown 888« and so on to distinct them for the users of the dimension. When a regular dimension has a hierarchy these levels can have text value »Unknown« as a special branch in the hierarchy.

 

Late arriving dimension

When a dimension data has been delayed:

a) If business key not exists then insert a new row.

b) If business key exists as an inferred member »Unknown« then type 1 update the row and type 2 insert a new row to keep history.

c) If business key exists and the delayed data comes with a date of valid then type 2 becomes more complex because validfrom and validto has to be adjusted and fact rows has to be revisited to update the dimension key column to point at the right dimension value at that date. You have to consider if it is allowed to change old data and old reporting result.

 

Late arriving fact

When a fact data has been delayed maybe it is including a date that can be used to search and fetch the current dimension member at that time if dimension keeps history. You have to consider if it is allowed to change old data and old reporting result.

 

Early arriving dimension

When a dimension has members that is not yet been referred to from a fact row or maybe it will never be i.e. a type of payment called »Blood«, but still keep it as a member of the dimension.

 

Other inferred members

Va­ri­e­ty of constant inferred members would be like:

»Missing« (0) the business key value is not present or hasn’t happened yet but is expected to be available later and at that time the value will get its own identity and fact table will be updated thereby.

»Not available« (-1) the source legacy system did not provide a business key value (null) and will not do it later. (»None« is another value).

»Not applicable« (-2) the dimension is not relevant for the fact row (N/A, N.A.). It is best to avoid a N/A dimension by making separate fact tables.

»Bad« or »Dirty« (-3) the source legacy system provide bad data (like year of birth as 2099) or not enough data to determine the appropriate dimension key identity. This may be due to corrupted data in the source legacy system or incomplete knowledge of the bu­si­ness rules for the source data for the dimension.

 

IsInferred flag

A dimension table can have different audit columns (see more in section 6.3) like a IsInferred flag as a boolean (bit) with two values (1 = true and 0 = false):

 

  • IsInferred = 1 means that the row represent an unknown value from source.
  • IsInferred = 0 means that the row represent a known value from source.

 

An example of a Customer dimension

 

Customer_key

Business_key

Region

Name

IsInferred

0

-999

Missing

Missing

1

1

176

Europe

Hans Andersen

0

2

359

North America

Joe Watson

0

3

421

Europe

Marie Beaulieur

0

134

886

Unknown

Unknown 886

1

135

887

Unknown

Unknown 887

1

136

888

Unknown

Unknown 888

1

137

889

East Asia

Jian Lewai

0

138

890

North America

Emily Gates

0

139

891

North America

Michael Brown

0

 

Will an inferred dimension member value data row be updated when the source legacy system provide a Region and a Name?

 

  • Yes, for type 1 the unknown value is updated and set IsInferred = 0.

 

  • No, for type 2 keep all values (incl. type 4, 5, 6, 7) because it is im­por­tant to keep history in rows, therefore the updated Region and Name will be inserted as a new data row with IsInferred = 0 and keep the original row of the dimension unchanged.

 

The fact table is untouched or unchanged because the foreign key Customer_key values 134 - 136 are at the right place already, it is only Unknown values of the dimension that is changed. Kimball says there is no need for revisiting the fact table for making an inferred member to a normal member of the dimension.

 

When other levels in a hierarchy has text value »Unknown« like Region and users of the dimension in a cube has already made reports with fact data connected to »Unknown«, it is important to keep the history in the dimension so an user some months later still can make the same report with same summary value »Unknown«. If an user instead want to use the current values of the previous inferred members, the cube should provide such a dimension too.

 

4.6. Conclusion

The design of a dimensional model has a four-step process described by Kimball:

1.  Select the business process to model by gathering and understanding business needs and available data in source legacy systems.

2.  Declare the grain of fact as Transaction, Periodic or Accumulating/Aggregated.

3.  Identify the dimensions with columns, hierarchy and group.

4.  Identify the facts with measures as additive or non-additive.

 

Dimensional modeling ends up in relational database tables for dimensions and facts with one-to-many relationships between primary keys and foreign keys, meaning it become an Entity Relationship data model where entities are labeled with Kimball naming.

 

An entity or table can have a normal name e.g. Product and Sales and they can be placed into different database schemas based on Kimball naming to labeling each table in the dimensional modeling e.g. of some database schema names:

 

  • Dim
  • Snowdim
  • Junkdim
  • Pcdim
  • Minidim
  • Bridge
  • Fact
  • Lessfact
  • Sumfact
  • Tnsfact
  • Ctpfact
  • Dvdfact

 

Extra schemas for Usage supporting tables in the ETL process:

 

  • Map    for mapping tables between different source legacy systems
  • Rule    for rule tables for enrichment of dimensions and search criteria

 

Other data modeler is adding a label Dim and Fact to the name of the table e.g. DimProduct and FactSales or Product_dim and Sales_fact.

 

The most important of all is a good table name e.g. in Kimball’s Healthcare example he has tables like:

 

  • Health Care Billing Line Item Fact
  • Surgical Events Transaction Fact
  • Medical Record Entries Fact
  • Hospital Dimension
  • Patient Dimension
  • Diagnosis Group Dimension
  • Diagnosis Group Bridge
  • Diagnosis Dimension
  • Treatment Dimension

 

Data Vault do also label entities or tables as hub (handling business key), link (many-to-many relationships) and satellite (data and one-to-many relationships).

 

5. Links for more readings

http://www.wikipedia.org/wiki/Data_warehouse

http://www.kimballgroup.com

http://www.kimballgroup.com/2009/05/the-10-essential-rules-of-dimensional-modeling/

http://www.kimballgroup.com/1997/08/a-dimensional-modeling-manifesto/

http://www.wikipedia.org/wiki/Slowly_changing_dimension

http://www.kimballgroup.com/2013/02/05/design-tip-152-slowly-changing-dimension-types-0-4-5-6-7

http://www.kimballgroup.com/2012/07/design-tip-147-durable-super-natural-keys/

http://www.kimballgroup.com/2015/12/design-tip-180-the-future-is-bright/

http://www.kimballgroup.com/wp-content/uploads/2007/10/An-Architecture-for-Data-Quality1.pdf

http://www.1keydata.com/datawarehousing/datawarehouse.html

https://www.youtube.com/watch?v=cwpL-3rkRYQ&list=PLrbIyvYCdg0iAUQoxG5vI_yKqzZ2AcgGe

 

Books:

Ralph Kimball and Margy Ross: The Data Warehouse Toolkit, The Definitive Guide to Dimensional Modeling, Third Edition, 2013.

Ralph Kimball and Joe Caserta: The Data Warehouse ETL Toolkit, Practical Techniques for Extracting, Cleaning, Conforming, and Delivering Data, 2004.

William H. Inmon: Building the Data Warehouse, Fourth Edition, 2005.

 

6. Examples with sample values

 

6.1. Customer snowflake dimension

Customer table in a source legacy system with CustomerId as a primary key (called Business key in a data warehouse or data mart) and CustomerNum­ber as a se­con­dary key including data of the nationality (country) and the gender of the customer (M or F):

 

CustomerId

CustomerNumber

CustomerName

176

DK-0912-M

Hans Andersen

359

US-3942-M

Joe Watson

421

FR-1429-F

Marie Beaulieur

422

FR-1430-M

Mathis Leon

 

Customer dimension table as a snowflake dimension:

 

Customer _key

Custo

merId

Customer

Number

Customer

Name

Country

_key

Gender _key

Payment _key

0

 

 

Missing

0

0

0

1

176

DK-0912-M

Hans Andersen

1

1

2

2

359

US-3942-M

Joe Watson

5

1

3

3

421

FR-1429-F

Marie Beaulieur

3

2

3

4

422

FR-1430-M

Mathis Leon

3

1

3

 

Customer_key is an unique sequence number as primary key for the dimension for ha­ving independence on the business key CustomerId from the source legacy system. From CustomerNumber I derived two extra columns for Country and Gender and they become snowflake dimensions and can be used together with other dimension tables and fact tables. Pay­ment is taking from another table in the CRM system and become a dimension itself and is merged into the Customer di­men­sion to do an enrichment of the customers. Country dimension has been en­riching inside the data warehouse by the business users with ISOcode and Cur­ren­cy values to fulfill repor­ting requirements. Each country is placed in a continent hie­rar­chy (Africa, Antarctica, Asia, Australia, Europe, North America and South America) in case a report want a continent overview of the customers and sales.

 

Country dimension table becomes an Outrigger dimension:

 

Country_key

Country

ISOcode

Currency

Continent

0

Missing

-

-

-

1

Denmark

DK

Danish Krone

Europe

2

England

UK

British Pound

Europe

3

France

FR

Euro

Europe

4

Norway

NO

Norwegian Krone

Europe

5

USA

US

United States Dollar

North America

6

China

CH

Renminbi

Asia

 

Gender dimension table:

 

Gender_key

Gender

0

Missing

1

Male

2

Female

3

Transgender

 

Payment dimension table with an extra data warehouse column to specify the sort order of payments for reporting purpose and a type hierarchy:

 

Payment_key

Payment

PaymentSortorder

PaymentType

0

Missing

9

-

1

Bank account

3

Transfer payment

2

Cash

1

Cash payment

3

Credit card

2

Online payment

4

PayPal

5

Online payment

5

Bitcoin

4

Online payment, virtual currency

 

For an olap multidimensional cube loading data to a Customer dimension will be implemented with a view that join the relevant tables and with several attributes and hierarchies to make an easy search and zoom into specific data in access data tools like Excel, Power BI, QlikView, Tableau or Targit:

 

Customer

·         Number

·         Name

·         Gender

·         Nationality (Country renamed to play a role)

·         Payment

 

In terms of granularity I want to see daily sales by customer and product for each individual employee which gives the grain declaration of date, customer, product, employee. The time-of-day from the operational system is left out so quantity has been summarized to date level in case a customer purchase the same product at the same employee in the one day e.g. 10.15am and 3.45pm.

An example of a sales statistic would be: »What is the amount of sale to female customers from France that have been paid with credit card in April 2014?«

We need a Sales fact table like this:

 

PurchaseDate

Customer_key

Product_key

Employee_key

Quantity

Amount

2014-04-23

2

256

12

1

125

2014-04-23

2

512

12

3

75

2014-04-24

3

128

7

7

10

2014-04-25

1

512

12

1

25

2014-04-29

3

64

10

2

35

2014-04-29

4

6

10

3

99

2014-04-30

0

19

0

1

0

 

The last row shows an unwanted sale because it is a stolen item therefore the cu­sto­mer is missing together with the amount.

 

A report want to show the total amount per gender including Trans­gen­der even though there is no customer yet. Since snowflaking has created a Gender di­men­sion with all genders independent of customer, a query will use an outer join to include all genders:

 

SELECT g.Gender, TotalAmount = ISNULL(SUM(s.Amount),0)

FROM Fact.Sales s

         INNER JOIN Dim.Customer c ON c.Customer_Key = s.Customer_key

         RIGHT OUTER JOIN Dim.Gender g ON g.Gender_Key = c.Gender_key

GROUP BY g.Gender_key

 

Gender

TotalAmount

Missing

0

Male

324

Female

45

Transgender

0

 

When snowflaking is not wanted for the Customer dimension, it will contain all the relevant descriptive columns:

 

Customer_key

CustomerId

CustomerNumber

CustomerName

Country

ISOcode

Currency

Continent

Gender

Payment

PaymentSortorder

PaymentType

 

The Customer dimension will contain re­dun­dant data i.e. a PaymentSortorder value is repeated for all the customers that is using same payment. One day business ask for a new sort order of payments because it will be more suitable for the reporting. I recommend to have a Usage supporting database in the data warehouse with tables where business users can update data through an application. With a Pay­ment table with columns Payment, PaymentSortorder and PaymentType a bu­si­ness user can change the values in column PaymentSortorder. The Usage supporting data­base will be a data source to the data warehouse where the ETL process will fetch the Payment table to the Input data area and the ETL process will update the Customer dimension table in the Data mart. Since business do not care of old sort order of payment, the column PaymentSortorder in Customer dimension will be treated as a type 1 column meaning a simple update of all the rows in the di­men­sion table.

In the Usage supporting database a business user can add extra data to the coun­tries and hereby enrich the reporting with data that doesn't e­xists in the sour­ce legacy systems.

Since there is no customer of Trans­gen­der, the value will not exists in the Customer dimension and therefore Trans­gen­der can’t been shown in a report except when it is added through a Union sql statement.

 

When all dimension values is wanted as fact, the fact table needs to include extra dimensions for Gender, Country and Payment and drop them from Customer.

 

6.2. Type 1, type 2 and type 7 with most recent current value

A customer has Id 421 in a source legacy system and her maiden name is Marie Beaulieur, and she is inserted into a Customer dimension. One day she gets married and takes her husband’s surname therefore her name is changed to Marie Lesauvage.

 

When the dimension is a type 1, her maiden name will be overwritten and will be forgotten. Customer_key is a surrogate key identity column a unique sequence number.

 

Before:

 

Customer_key

Business_key

CustomerName

1

176

Hans Andersen

2

359

Joe Watson

3

421

Marie Beaulieur

 

After:

 

Customer_key

Business_key

CustomerName

1

176

Hans Andersen

2

359

Joe Watson

3

421

Marie Lesauvage

 

The type 1 dimension will always show the customers most recent name (cur­rent or latest name). A Customer_key column will be in a fact table and in a data access tool like Tableau and QlikView fact column Customer_key will be joined to di­men­sion column Customer_key inside the tool’s data model.

 

When the dimension is a type 2, her maiden name will remain and will be remembered and her changed name will continue in an extra row. To keep track of when a value is changed, there is two datetime columns called ValidFrom and ValidTo. Her maiden name was valid from the beginning of time e.g. 2000-05-08 (if no entry date in source legacy system then use 1900-01-01) and valid to until 2007-11-16 meaning not included, because she got married at 2007-11-16 and changing her name is valid from that date until the end of time e.g. 9999-12-31.

 

Customer_key

Business_key

CustomerName

ValidFrom

ValidTo

1

176

Hans Andersen

1997-04-05

9999-12-31

2

359

Joe Watson

2000-01-12

9999-12-31

3

421

Marie Beaulieur

2000-05-08

2007-11-16

4

421

Marie Lesauvage

2007-11-16

9999-12-31

 

Note: Kimball page 508: If ValidFrom and ValidTo are datetime stamps then the ValidTo must be set to exactly the ValidFrom of the next row so that no gap exists between rows and no overlap too with continuous time. Other kind of time is event time (in a point of time) and interval time with gaps or overlap.

 

[In danish we say that ValidFrom is »fra og med« og ValidTo is »til og ikke medtaget« because the second row with same datetime in ValidFrom as the above ValidTo is representing a new period from that datetime.]

 

Marie Lesauvage remarried at 2014-07-15 and took her new husband’s surname therefore her name is changed to Marie Sainte and become a new row in the table.

 

Customer_key

Business_key

CustomerName

ValidFrom

ValidTo

1

176

Hans Andersen

1997-04-05

9999-12-31

2

359

Joe Watson

2000-01-12

9999-12-31

3

421

Marie Beaulieur

2000-05-08

2007-11-16

4

421

Marie Lesauvage

2007-11-16

2014-07-15

5

421

Marie Sainte

2014-07-15

9999-12-31

 

The Business_key column is the »glue« that holds the multiple records together.

 

A dimension can have extra columns for audit, housekeeping, support as IsCurrent, IsDelete, IsInferred or a Status column with values e.g. Current, Deleted, Expired.

 

Marie has made six purchases which is entered into a fact table where her date of purchase­ determines the value in column Customer_key after this rule:

 

   ValidFrom <= PurchaseDate AND ValidTo > PurchaseDate

 

PurchaseDate

Customer_key

Product_key

Quantity

Amount

2005-11-10

1

21

1

45

2005-11-10

2

29

2

140

2005-12-01

3

32

2

200

2010-06-30

4

17

1

65

2014-05-08

4

32

3

300

2014-08-01

5

21

2

90

2016-03-15

5

29

1

70

2016-03-15

5

32

1

100

 

For each row in the fact table the value in column Customer_key is pointing to a row in the dimension table and give the name of the customer at the time the purchase occurred or was registered. Customer_key column in fact table represent as-was when it is joined to the dimension table.

 

When a report of purchase­s wants to show the customers most recent name (cur­rent or latest name) independent of the purchase date e.g. 2005-12-01 has Customer_key value 3 but must show the latest name of Marie with value 5. It is normally solved with a database view that find the most recent CustomerName for each value of Custo­mer_key with this result:

 

Customer_key

CustomerName

1

Hans Andersen

2

Joe Watson

3

Marie Sainte

4

Marie Sainte

5

Marie Sainte

 

A type 2 current view dimension can be implemented like this:

 

CREATE VIEW DimCustomer_Current AS

SELECT d.Customer_key, c.CustomerName

FROM DimCustomer d

         INNER JOIN

         (SELECT Business_key, CustomerName

          FROM DimCustomer

          WHERE ValidTo = '9999-12-31'  -- datetime2(7) '9999-12-31 23:59:59.9999999'

         ) c ON c.Business_key = d.Business_key

 

The view will do a query for always to select the current value for each key values in the dimension and show the result set or recordset as showned in the table above.

 

If your sql has windowing function the view can avoid the self join which will en­han­ce performance and here is no use of ValidTo column:

 

CREATE VIEW DimCustomer_Current AS

SELECT Customer_key, CustomerName = LAST_VALUE(CustomerName)

            OVER(PARTITION BY Business_key ORDER BY ValidFrom

            ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)

FROM DimCustomer

 

Use the view in a join with the fact table to fetch the current value for each fact row:

 

SELECT c.CustomerName, f.Quantity, f.Amount

FROM FactSales f

         INNER JOIN DimCustomer_Current c ON c.Customer_key = f.Customer_key

 

Customer_key column from the view represent as-is for most recent data when it is joined to the fact table.

 

The disadvance of the first view for current value of the dimension is the join on the business key because it can be a string representation or a composite business key as composed of multiple columns that needs to be part of the inner join columns, which can cost performance when the dimension has many rows. With type 7 dimension Kimball introducing an integer representation of the business key and he called it durable key, an artificial surrogate key value per business key, see later.

The disadvance of the second view is that the windowing function must be used for each column that is wanted to be displayed for the dimension.

 

Temporal tables in SQL Server 2016 is closest to type 4 because keeping history in the separate table while original dimension table keeps current dimension member, more reading.

 

In case you want to display the original value of the dimension as type 0:

 

CREATE VIEW DimCustomer_Original AS

SELECT Customer_key, CustomerName = FIRST_VALUE(CustomerName)

            OVER(PARTITION BY Business_key ORDER BY ValidFrom

            ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)

FROM DimCustomer

 

Use the dimension table in a join with the fact table to fetch registered value for each fact row:

 

SELECT c.CustomerName, f.PurchaseDate, f.Quantity, f.Amount

FROM FactSales f

         INNER JOIN DimCustomer c ON c.Customer_key = f.Customer_key

 

Customer_key column from the table of dimension represent as-was when the fact row was entered into the fact table when the data occurred.

 

There is another type 2 approach that do not need the ValidTo column in the dimen­­sion table and therefore the ETL process shall not update the previous row, because a ValidTo column can be calculated when it is needed to determine the dimension key for the coming fact row:

 

CREATE VIEW DimCustomer_ValidTo AS

SELECT Customer_key, CustomerName, ValidFrom,

            ValidTo = LEAD(ValidFrom, 1, '9999-12-31')

            OVER(PARTITION BY Business_key ORDER BY ValidFrom)

FROM DimCustomer

 

In a data access tool like Tableau and QlikView the type 2 for showing most recent values needs two views that will inside the tool’s data model be joined together. A user can in a dropdown box select Marie Sainte (me­a­ning Customer_key value 5) and all her fact six purchases will be shown or a sum of Amount even though she has changed her name over time. The dimension for current customers will show this unique list of most recent customers in a dropdown box based on a view:

 

Customer

_Current

_key

CustomerName

1

Hans Andersen

2

Joe Watson

5

Marie Sainte

 

CREATE VIEW dma.DimCustomer_Current AS

SELECT Customer_key AS Customer_Current_key, CustomerName

FROM DimCustomer

WHERE ValidTo = '9999-12-31'  -- datetime2(7) '9999-12-31 23:59:59.9999999'

 

The fact will show this through a view that include a Customer_Current_key column to be joined to the view DimCustomer_Current in the tool’s data model:

 

PurchaseDate

Customer

_key

Customer

_Current

_key

Product

_key

Quantity

Amount

2005-11-10

1

1

21

1

45

2005-11-10

2

2

29

2

140

2005-12-01

3

5

32

2

200

2010-06-30

4

5

17

1

65

2014-05-08

4

5

32

3

300

2014-08-01

5

5

21

2

90

2016-03-15

5

5

29

1

70

2016-03-15

5

5

32

1

100

 

CREATE VIEW dma.FactSales AS

WITH DimCustomer_Current (Customer_key, Customer_Current_key) AS

(

SELECT Customer_key,

            MAX(Customer_key) OVER(PARTITION BY Business_key) AS Customer_Current_key

FROM DimCustomer

)

SELECT f.PurchaseDate, f.Customer_key, c.Customer_Current_key, f.Product_key,

            f.Quantity, f.Amount

FROM FactSales f

         INNER JOIN DimCustomer_Current c ON c.Customer_key = f.Customer_key

 

When current customer Marie Sainte is selected in a dropdown box, the tool will do a query based on the tool’s data model to show all her six purchases even though she has changed her name over time:

 

SELECT c.CustomerName, f.PurchaseDate, f.Quantity, f.Amount

FROM dma.FactSales f

         INNER JOIN dma.DimCustomer_Current c

           ON c.Customer_Current_key = f.Customer_Current_key

WHERE c.CustomerName = 'Marie Sainte'

 

CustomerName

PurchaseDate

Quantity

Amount

Marie Sainte

2005-12-01

2

200

Marie Sainte

2010-06-30

1

65

Marie Sainte

2014-05-08

3

300

Marie Sainte

2014-08-01

2

90

Marie Sainte

2016-03-15

1

70

Marie Sainte

2016-03-15

1

100

 

The fact view is still keeping the Customer_key column to be joined to the Cu­sto­mer dimension for showing the name of a customer when the purchase was hap­pe­ning.

The view dma.FactSales is using a With part (Common Table Expression) to make a tem­porary result set. It could be changed to a materialized view which store data in a table with a clustered primary key through the ETL process and table FactSales will join to that table to get a better performance.

 

When the dimension is a type 7 it does the same as type 2 with an extra column called Durable key that is an integer re­pre­sen­tation of the business key because a business key could be a mix of number and text and could be a composite key.

 

Customer

_key

Customer

_Durable

_key

Business

_key

CustomerName

ValidFrom

ValidTo

1

1

176

Hans Andersen

1997-04-05

9999-12-31

2

2

359

Joe Watson

2000-01-12

9999-12-31

3

3

421

Marie Beaulieur

2000-05-08

2007-11-16

4

3

421

Marie Lesauvage

2007-11-16

2014-07-15

5

3

421

Marie Sainte

2014-07-15

9999-12-31

 

The Durable key will also appear in the fact as a dual foreign key for a given dimen­sion.

 

PurchaseDate

Customer

_key

Customer

_Durable

_key

Product

_key

Quantity

Amount

2005-11-10

1

1

21

1

45

2005-11-10

2

2

29

2

140

2005-12-01

3

3

32

2

200

2010-06-30

4

3

17

1

65

2014-05-08

4

3

32

3

300

2014-08-01

5

3

21

2

90

2016-03-15

5

3

29

1

70

2016-03-15

5

3

32

1

100

 

The Durable key will also appear in the current view that will show each customer in a unique list of most recent customers.

 

Customer

_Durable

_key

CustomerName

1

Hans Andersen

2

Joe Watson

3

Marie Sainte

 

A type 7 current view dimension can be implemented like this:

 

CREATE VIEW DimCustomer_Current AS

SELECT Customer_Durable_key, CustomerName

FROM DimCustomer

WHERE ValidTo = '9999-12-31'  -- datetime2(7) '9999-12-31 23:59:59.9999999'

 

The Durable key will also appear in a join with the fact table to fetch the current value for each fact row:

 

SELECT c.CustomerName, f.PurchaseDate, f.Quantity, f.Amount

FROM FactSales f

         INNER JOIN DimCustomer_Current c

           ON c.Customer_Durable_key = f.Customer_Durable_key

 

In a data access tool like Tableau and QlikView the type 7 current view become a dimension of most recent values and inside the tool’s data model the view is joined to the fact table’s durable key column. A user can in a dropdown box select Marie Sainte (me­a­ning Customer_Durable_key value 3) and all her fact six purchases will be shown or a sum of Amount even though she has changed her name over time.

 

The advance with type 7 is that the business key from a source legacy system is not part of a query to fetch the most recent values from a dimension. See more about SCD type 7 dimension in next section.

 

6.3. Kimball type 7 dimension

A type 7 dimension will keep all values in a dimension independent of the source legacy system with an option to easy to roll up historical facts based on current dimension characteristics. It is formerly known as »Compliance-Enabled Data Warehouses« at Kim­ball Design Tip #74 that achieve:

 

·      Eliminating Type 1 and Type 3 updates.

·      Accessing all prior versions of a database at points in time.

·      Protecting the custody of your data.

·      Showing why and when changes to data occurred.

 

In this section, I like to give my description of the dimension type 7.

 

I will start with the life cycle terms for a value (member) in a dimension:

 

·      Original is the value of birth when it occurred and entered first time.

·      Historical is tracking the value for changes (modified/updated) at any time.

·      Current is active, newest, latest of the value or most recent indicator.

·      Deleted is the value no longer available in the source legacy system.

 

From a fact data point of view it is important to know the value of a dimension at the time of registration, therefore I will add to the life cycle:

 

·      Registered is the dimension value when the fact data occurred or entered.

 

There will probably be dimension values that will not be used in fact data.

 

When I have one fact data row in my hand, I can provide four versions of the va­lue in a dimension, can also be called four perspectives:

 

·      Registered is the dimension value when the fact data row was registered or entered into the data warehouse with a transaction date or an insert time.

·      Current is the latest and active dimension value and thus independent of the time of registration of the fact data row.

·      Original is the entered first time dimension value maybe even before the fact data row exists in the source legacy system.

·      Historical is the dimension value at a specific given date reporting point-in-time datetime independent of the fact transaction date.

 

Registered stands for as-was when occurred, Current stands for as-is for most recent data, Historical stands for as-of a specific particular reporting date and Original stands for as-began when the data value was born.

 

An additional information for the fact data row would be about the dimension value is not longer available in source legacy system because it has been marked expired or purged or it has been deleted.

 

My design pattern for type 7 dimension will have extra key audit columns or house­kee­ping columns or support columns or administrative columns:

 

·         _key stands for a primary key column which is a new integer surrogate num­ber e­ve­ry time a va­lue in a source legacy system is changed and send to the data warehouse. The key is an unique iden­tity auto increment se­quen­tial number normally starting from 1. Can be called _skey for sur­ro­gate key or even better _rkey for the registered key reference from a fact table row to the dimension table row with the textual data descriptive attri­bu­tes at the time the fact data row was registered or entered into the data warehouse.

 

·         _dkey stands for a durable key which is not a unique integer number per row, instead it will hold the same number as the _key column when the dimension value entered the di­men­sion table for the first time and that number will be repeated every time the value change. Can be called _ekey for entity key becau­se the unique number of _dkey is also an unique in­de­pen­dent data ware­house surrogate number for the business key which is unique in the so­ur­ce legacy system like a primary key. Sometimes called a stable key. Can also be called _hkey for history reference over time used for look up in dimen­sion for the current value, for the original value when it was entered the first time or for the historical value at a specific reporting datetime point-in-time.

 

·         _pkey stands for a previous key (or parent-child key) which is a re­fe­ren­ce to a _key value for the previous or latest version of a dimension value when a value change over time. It is a referential integrity where _pkey is a foreign key to primary _key with one ex­cep­tion that value 0 in _pkey does not has a reference to a _key value because value 0 represent the first time the dimension value enter the dimension table and therefore has no previous value and that is the same as the original value.

 

·         _bkey stands for a business key which is unique in the so­ur­ce legacy sy­stem like a primary key. A composite business key is composed of multiple columns like Name_bkey + Street_bkey + Zip­code_bkey and they will be multiple columns in the dimension table. Sometimes a string concatenation with a separator character to handle them in one _bkey column to compare with source data. Identical data can exists in multiple source legacy sy­stems like an employee in CRM, ERP and HR with their own business key in the Employee dimension through sibling columns like CRM_bkey, ERP_bkey and HR_bkey with different representation like a number, a code and an e­mail address. Depen­ding of complexity there is a need of a mapping table in the data warehouse to take care of the merge of business keys and some­times it is a manual task to merge data together when there is no sui­table natural key. Importance is to have an employee as one entity with one durable sur­rogate number for the combination of business keys making a one-to-one relationship between _bkey and _dkey. Examples of con­cate­na­ted string column that can be used together with a checksum column cal­led _Comparison that represent the other columns outside the source pri­mary key:

concat(Name_bkey,'¤',Street_bkey,'¤',Zip­code_bkey)

concat(Id,'¤',Date,'¤',Step)

cast(hashbytes('sha2_256', concat(FirstName, LastName)) as binary(32))

used to find out when data has been changed in the source legacy system to make a new row in dimension with new validfrom/validto in the ETL pro­cess.

 

·         _nkey stands for a natural key which is unique in the so­ur­ce legacy sy­stem like a candidate key or a secondary key and can be needed to con­form a dimension across multiple so­ur­ce legacy systems which have their own business key that can’t be used in the merge because it is a sur­ro­gate key i­den­tity column a unique sequence number.

 

An example

Lets have an example where a source legacy system has changed its value three times from »Warning« to »Notification« and to »Caution«. Each of the three values become a new row in a dimension table together with two audit co­lumns that representing the period for which the value was found in the sour­ce legacy system, here called:

 

·         ValidFrom  also called EffectiveDate or StartDateTime or BeginDateTime.

·         ValidTo      also called ExpirationDate or StopDateTime or EndDateTime.

 

In a dimension table of type 7 it will look like this with audit columns and one business key column and one text value column in a System dimension:

 

System

_key

System

_dkey

System

_pkey

System

_bkey

System

ValidFrom

ValidTo

19

19

0

76CB

Warning

1900-01-01

00:00:00

2015-05-08

14:12:21

35

19

19

76CB

Notification

2015-05-08

14:12:21

2015-07-31

08:45:48

87

19

35

76CB

Caution

2015-07-31

08:45:48

9999-12-31

00:00:00

 

Column _key is an unique primary key of the dimension table and the com­bi­nation of _bkey + ValidFrom or _bkey + ValidTo is unique too.

 

[I prefer to think a table of a dimension as an object that has its own functions on data, therefore I like to have _key and _dkey to start from 1 for each dimen­sion instead of having a dimension key store map with a global number for all the keys across all the dimensions where each business key will get its own surrogate key and a new dimension table will start with a _key like 4983562.]

 

»Warning« and »Notification« is history va­lues of the System dimension and »Caution« is the most recent indicator of the System dimension with these terms:

 

·         »Warning« is the original value.

·         »Notification« is the historical value.

·         »Caution« is the current va­lue.

·         »?« is the registered value depend of the transaction date in the fact row.

 

The challenge is that you have to choose which version of a dimension value you like to present in your report.

 

Registered value

From a source legacy system the data warehouse has received two outages fact data with an OutageDate (kind of a transaction date) and a SystemId business key that match to System_bkey in the System dimension. Example of two source data rows:

 

OutageDate

SystemId

ProductionKWh

2015-05-25 10:22:43

76CB

173

2015-08-02 15:47:10

76CB

221

 

For each source data row the value of OutageDate will look up in the System dimension at the time when the outage was happening to determine and fetch the correct dimension value. The fact data row is registered with criteria like:

 

System_bkey = SystemId AND

ValidFrom <= OutageDate AND ValidTo > OutageDate

 

It will select one row from the dimension table and the values of columns Sy­stem_key and Sy­­stem_dkey will be copied to the new fact row, like for these two outages incidents at Maj 25 and August 2 in 2015 will become two fact data rows:

 

OutageDate

System_key

System_dkey

ProductionKWh

2015-05-25 10:22:43

35

19

173

2015-08-02 15:47:10

87

19

221

 

System_key is a reference to the System dimension value at the registered fact time from column OutageDate, and System_dkey is a reference to the entity with business key 76CB to provide current, original or historical value.

 

When we like to see the value from the dimension at the time where an outage happen, fact table column System_key will join to the dimension column Sy­stem_key and get the value from the unique row. We call this value the registered value, because it was the value of the dimension when the outage incidents was occurred, and the value will never change because the dimension is handling all changes of va­lues.

Fact table join to the dimension table to fetch registered value:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System d ON d.System_key = f.System_key

 

System

OutageDate

ProductionKWh

Notification

2015-05-25 10:22:43

173

Caution

2015-08-02 15:47:10

221

 

Here we see the purpose of the OutageDate and in case of the source legacy sy­stem does not provide a »transaction date« to determine and fetch the dimension value, the data warehouse will use a Fact_RegisteredTime (receipt datetime, createddate, inserttime, current_time­stamp, getdate, sysdatetime) for when the fact data is regi­stered or entered into the fact table row with criteria like:

 

System_bkey = SystemId AND

ValidFrom <= Fact_RegisteredTime AND ValidTo > Fact_RegisteredTime

 

Current va­lue

It can sometimes confuse users because the value of System has changed over time, and what is the summation of ProductionKWh of the System when using the registered value? Therefore we can provide the current value of the System dimension.

Fact table join to the dimension table to fetch current value:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System d ON d.System_dkey = f.System_dkey AND

                              d.ValidTo = '9999-12-31 00:00:00'

 

System

OutageDate

ProductionKWh

Caution

2015-05-25 10:22:43

173

Caution

2015-08-02 15:47:10

221

 

And a summation of ProductionKWh is 394 KWh for Caution.

 

Original value

We can provide an original value of the System dimension.

Fact table join to the di­men­sion table to fetch original value:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System d ON d.System_dkey = f.System_dkey AND

                              d.System_pkey = 0           (d.System_key = d.System_dkey)

 

System

OutageDate

ProductionKWh

Warning

2015-05-25 10:22:43

173

Warning

2015-08-02 15:47:10

221

 

And a summation of ProductionKWh is 394 KWh for Warming, which is the original value of the system, maybe some users remember it best.

 

Historical value

We can provide a historical value of the System dimension at a specific given as-of date reporting point-in-time datetime (ReportTime, Reque­sted­Date) that will be part of the criteria.

Fact table join to the di­men­sion table to fetch historical value:

 

DECLARE @ReportTime datetime = '2015-06-01 10:24:47'

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System d ON d.System_dkey = f.System_dkey AND

                              d.ValidFrom <= @ReportTime AND d.ValidTo > @ReportTime

 

System

OutageDate

ProductionKWh

Notification

2015-05-25 10:22:43

173

Notification

2015-08-02 15:47:10

221

 

The »between-filter« do the constrained to a single version value of system. A re­por­ting datetime at »June 1, 2015, 10.24« will fetch sy­stem Notification and that will never change even though the system name changes value over time. It means I can always repeat and reprocedure my report as long as I remember the reporting datetime. If I choose another reporting datetime like »September 1, 2015, 09.46« it will fetch system Caution. The reality with this approach is that you have a many-to-many relationship between the fact table and the dimension, so you must force your delivery reporting tools to choose an as-of date to allowing point-in-time analysis at a given date to avoid bringing back all combinations and resulting in overstated measurements.

 

Helper views

It is hard to remember the criteria for _key, _dkey, ValidTo and ValidFrom therefore I will make four sql helper views to make the join between dimension and fact more easy for users and analysis tools:

 

Current view

 

CREATE VIEW dim.System_Current AS

SELECT System_dkey, System

FROM   dim.System

WHERE ValidTo = '9999-12-31 00:00:00'

 

The view will do a query for always to select the current value for each values in the dimension.

 

Used in join with fact table to fetch current value for a fact row:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System_Current d ON d.System_dkey = f.System_dkey

 

Let us imagine we are back in time at June 5, 2015 and we like to see in Tableau the current sy­stem of the outage at May 25, the view System_Current will provide system Noti­fi­ca­tion because that was the current value at that time. When we do the same in Tableau at August 22, the view System_Current will provide sy­stem Caution. Fact table co­lumn Sy­stem_dkey will join to the view column System_dkey and it will provide dif­fe­rent values from the dimension depend of the date and time we do the reporting in Tableau and the values will always be the current and most recent.

 

A dimension is used to search for data rows from a fact table and with the view Sy­stem_Cur­rent it is easy inside Tableau and QlikView to make a dimension for recent values and join it to the fact through the column System_dkey in the tool’s data model. Tableau and QlikView shows the most recent values of System e.g. Caution and a user select the value in a dropdown as a criteria, and Tableau and QlikView do a join to the fact table and find all the data rows that is using this system even though the name of system has been changed over time:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System_Current d ON d.System_dkey = f.System_dkey

WHERE d.System = 'Caution'

 

In Tableau and QlikView the dimension would be named Current_System.

 

Registered view

 

CREATE VIEW dim.System_Registered AS

SELECT System_key, System

FROM   dim.System

 

Used in join with fact table to fetch registered value for a fact row:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System_Registered d ON d.System_key = f.System_key

 

In Tableau and QlikView the dimension would be named Registered_System and it is used to report a name of a system when the Outage was happening.

 

Original view

 

CREATE VIEW dim.System_Original AS

SELECT System_dkey, System

FROM   dim.System

WHERE System_pkey = 0          (System_key = System_dkey)

 

Used in join with fact table to fetch original value for a fact row:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System_Original d ON d.System_dkey = f.System_dkey

 

Seldom to have an Original_System dimension in Tableau but we can if we want.

 

Historical function with a datetime parameter

 

CREATE FUNCTION dim.System_Historical(@ReportTime datetime)

RETURNS TABLE AS RETURN (

SELECT System_dkey, System

FROM   dim.System

WHERE ValidFrom <= @ReportTime AND ValidTo > @ReportTime)

 

Used in join with fact table to fetch historical value for a fact row with a datetime:

 

SELECT d.System, f.OutageDate, f.ProductionKWh

FROM    fact.Outage f

            INNER JOIN dim.System_Historical('2015-06-01 10:24') d

               ON d.System_dkey = f.System_dkey

 

Tableau and QlikView does not yet offer a user typein datetime value for a di­men­sion before dis­play­ing the values of the dimension, but a report has normally some criteria boxes and one of them could be an input datetime for a historical di­men­sion, so the report shows the values from a specific point-in-time, maybe to re­pro­duce exactly the sa­me report as it was made before at that time.

 

I could instead have made four database shemas like: dimregistered, dimcurrent, dimoriginal and dimhistorical and reused the view name System.

 

Conclusion

Dimension type 7 provides up to four values for registered, current, original and hi­storical and it is very flexible for a fact data row to request for and fetch a di­men­sion value. Of course a lot of fact data rows have only one value in a di­men­sion, like a fact for sale to a new customer that is at the same time entered into the dimension. When the customer don’t change any data for a long time, the di­men­sion value is regi­stered = current = original = historical. The cu­stomer purchases many times and have many rows in sales fact, but one day the customer moves from his home country to three different countries over time and still continue to purchase. This means that the original value become the home country, historical values is the second and third country, and current value is the fourth and recent country, and the registered value country is depending of the date of the sale. For statistics of the sales we can have summaries for customers home countries even though they have moved to other countries because we simple use the original value of the dimension. We can have summaries for countries where the customer did their purchase from by using the registered value. In case we like to know the sales from customers who have once lived in a specific country, we first look up that country in the customer dimension and gets their _dkey’s and join them to the fact sale table. The marketing people like to know the current address, phone number and email of all the customers to contact them with new exciting offers. Type 7 gives you all the options and the four helper sql views is handy for ad hoc queries. The right information, at the right time, in the right place, in the right way, in the right format, to the right person. In a data access tool like Excel, Power BI, QlikView, Tableau or Targit it is easy to make dimensions based on the helper views and join the dimensions to the fact through the dkey or key columns in the tool’s data model.

 

Dimension table and Fact table

A dimension table in the physical design will have extra key audit columns or house­kee­ping columns or support columns or administrative columns:

 

·         _key    used for the registered fact data value of the dimension.

·         _dkey  used for the current, original and historical value of the dimension.

·         _pkey  used for the previous key that is a reference to the _key column.

·         _bkey  used for the business key from the so­ur­ce legacy system.

·         _nkey  used for the natural key from the so­ur­ce legacy system.

 

A fact table in the physical design has for each dimension two audit columns:

 

·         _key    used for the registered fact data value of the dimension.

·         _dkey  used for the current, original and historical value of the dimension.

 

A dimension table will keep track of datetime stamp of inserting and updating a row with two audit columns:

 

·         InsertTime    database server system time when the row was inserted.

·         UpdateTime   database server system time when the row was updated.

 

I don’t like an audit column to be Null or N/A, therefore UpdateTime gets the same datetime stamp as InsertTime, so both columns will have the same value until data in the row will be either changed or deleted in the source legacy system. The two audit columns can be assigned either by triggers for insert and update at the table or by the ETL process. I prefer the ETL process to handle all audit columns.

 

A dimension table will keep track of a current value in the source legacy system with an audit column which is a boolean (bit) with two values (1 = true and 0 = false):

 

IsCurrent

IsCurrent = 1 means that the row represent the current value from source system.

IsCurrent = 0 means that the row represent a historical value from source system.

 

Column IsCurrent can also be called NewestFlag, ActiveFlag or RecentFlag.

 

When IsCurrent = 1 the ValidFrom/ValidTo represent the period where the row va­lue is current in the source legacy system.

 

A dimension table will keep track of an expired or deleted value in the source le­gacy system with an audit column which is a boolean (bit) with two values (1 = true and 0 = false):

 

IsDeleted

IsDeleted = 1 means that the row represent the deleted value from source system.

IsDeleted = 0 means that the row represent an existing value from source system.

 

Column IsDeleted can also be called DeleteFlag, DeletedAtSource, ExpiredFlag or InactiveFlag, when data are deleted in a system and therefore are gone forever.

 

When IsDeleted = 1 the ValidFrom/ValidTo represent the period where the row va­lue does not exists in the source legacy system.

 

A dimension table can keep track of the reason why the row was changed in a co­lumn called RowChangeReason so it is easy for doing search and analysis. The column could have value »New« when the row represent a new customer, and later when customer move to another country the value could change to »Moved country« and later it would be »Changed credit status« and so on.

 

A fact table will keep track of datetime stamp of inserting a row with audit column:

 

·         InsertTime  database server system time when the row was registered.

 

When there is no transaction date for a fact data the InsertTime will be used to look up an unique dimension table row. Sometimes the term RegisteredTime is used.

 

A fact table will keep track of datetime stamp of updating a row with audit co­lumns:

 

·         UpdateTime  database server system time when the row was updated.

·         IsCurrent      if fact row will change then keep track of current row.

·         IsDeleted      if fact row can be deleted from source legacy system.

·         ValidFrom     if fact row is treated as SCD type 2, Slowly Changing Facts.

·         ValidTo         if fact row is treated as SCD type 2, Slowly Changing Facts.

 

Slowly Changing Facts SCF or Frequently Changing Facts FCF but hopefully not Rapidly Changing Facts RCF because that could give a lot of facts rows over time.

 

When transactions are changed retroactively, you should update corresponding fact rows. If you need to track the history of fact rows it become Slowly Changing Facts, see more in section 6.4.

 

A developer like to prefix or postfix all key and audit columns to make sure that the source legacy system does not have a column with the same name. A postfix would be like _dw or _dwh.

 

An example

Lets have an example where a source legacy system has changed its value three times from »Warning« to »Notification« and to »Caution« and in the ending the source legacy system will delete the value so it will not exists anymore, but the dimension will keep it forever. Each of the following steps will show how the dimension table looks like after each process has been done.

 

1. First time a value arrives to the data warehouse which happen at Maj 1, 2015, 5 pm or 17:00, a new row is added to the dimension table to contain the new value in column System to­gether with ten audit columns:

 

_key

_dkey

 

_pkey

 

_bkey

System

ValidFrom

ValidTo

IsCurrent

IsDeleted

InsertTime

UpdateTime

19

19

0

76CB

Warning

1900-01-01

00:00:00

9999-12-31

00:00:00

1

0

2015-05-01

17:00:00

2015-05-01

17:00:00

 

2. Value changed at 2015-05-08 therefore the first row is not current and a new row is added:

 

_key

_dkey

 

_pkey

 

_bkey

System

ValidFrom

ValidTo

IsCurrent

IsDeleted

InsertTime

UpdateTime

19

19

0

76CB

Warning

1900-01-01

00:00:00

2015-05-08

14:12:21

0

0

2015-05-01

17:00:00

2015-05-08

17:01:09

35

19

19

76CB

Notification

2015-05-08

14:12:21

9999-12-31

00:00:00

1

0

2015-05-08

17:01:10

2015-05-08

17:01:10

 

3. Value changed at 2015-07-31 therefore the second row is not current and a new row is added:

 

_key

_dkey

 

_pkey

 

_bkey

System

ValidFrom

ValidTo

IsCurrent

IsDeleted

InsertTime

UpdateTime

19

19

0

76CB

Warning

1900-01-01

00:00:00

2015-05-08

14:12:21

0

0

2015-05-01

17:00:00

2015-05-08

17:01:09

35

19

19

76CB

Notification

2015-05-08

14:12:21

2015-07-31

08:45:48

0

0

2015-05-08

17:01:10

2015-07-31

14:03:22

87

19

35

76CB

Caution

2015-07-31

08:45:48

9999-12-31

00:00:00

1

0

2015-07-31

14:03:23

2015-07-31

14:03:21

 

4. Value deleted at 2015-08-06 where the current row will be copied to a new row mark deleted:

 

_key

_dkey

 

_pkey

 

_bkey

System

ValidFrom

ValidTo

IsCurrent

IsDeleted

InsertTime

UpdateTime

19

19

0

76CB

Warning

1900-01-01

00:00:00

2015-05-08

14:12:21

0

0

2015-05-01

17:00:00

2015-05-08

17:01:09

35

19

19

76CB

Notification

2015-05-08

14:12:21

2015-07-31

08:45:48

0

0

2015-05-08

17:01:10

2015-07-31

14:03:22

87

19

35

76CB

Caution

2015-07-31

08:45:48

2015-08-06

10:10:05

0

0

2015-07-31

14:03:23

2015-08-06

12:00:06

99

19

87

76CB

Caution

2015-08-06

10:10:05

9999-12-31

00:00:00

1

1

2015-08-06

12:00:08

2015-08-06

12:00:05

 

With this approach there will be inserted an additional row for a deleted (or closed item) in the so­ur­­ce legacy system, so the dimension will tell in the last row which is mark as deleted, a period where the value is deleted from 2015-08-06 10:10:05 to forever. IsDelete = 1 represent a deleted  row or record or data in the source legacy system, therefore the business key is no longer available in source legacy system in the period of ValidFrom/ValidTo. We asume the value will not be reopen (or reborn) with the same business key in the source legacy system. No fact data with a _key co­lumn will never point to or refer to a deleted value in a dimension, therefore no fact row can use a _key value with IsDeleted = 1. IsCurrent = 0 represent the old historical version of the value and ValidFrom/ValidTo tells us the period when the old value was current or active back in time. Since older fact data can be refering by column _dkey to a deleted dimension value, it is still needed to have IsCurrent = 1, and with IsDeleted = 1 we can see that the value is not available in the source legacy system. Therefore a fact table data is consistent (not inconsistent) and will never be missing a dimension value in a dimension table.

 

When source data with an OutageDate arrives to the data warehouse it will find the historical system name at the time when the outage was happening with a criteria that will not include the dele­ted dimension value because a fact data with a _key column can’t refer to a deleted value:

 

IsDeleted = 0 AND System_bkey = SystemId AND

ValidFrom <= OutageDate AND ValidTo > OutageDate

 

Example of two source data rows:

 

OutageDate

SystemId

ProductionKWh

2015-05-25 10:22:43

76CB

173

2015-08-02 15:47:10

76CB

221

 

Become two fact data rows where System_key is a reference to the System dimension value at the registered fact time from column OutageDate and System_dkey is a reference to the entity with business key 76CB to provide current, original or historical value.

 

OutageDate

System_key

System_dkey

ProductionKWh

2015-05-25 10:22:43

35

19

173

2015-08-02 15:47:10

87

19

221

 

The current view for the dimension to show all current values from the dimension will search after criteria IsCurrent = 1, so the view gives the current value every time I access the view, and the fact co­lumn _dkey can join to the view for showing the current va­lues of the dimension, therefore dimen­sion values with IsDeleted = 1 will be included in the view because there are old fact data back in time with a _dkey which refer to a deleted dimension data in the source legacy system.

 

View provide registered dimension values and will be joined to fact data through _key

 

CREATE VIEW dim.System_Registered AS

SELECT System_key, System

FROM   dim.System

WHERE IsDeleted = 0

 

View provide current dimension values and will be joined to fact data through _dkey

 

CREATE VIEW dim.System_Current AS

SELECT System_dkey, System

FROM   dim.System

WHERE IsCurrent = 1

 

View provide original dimension values and will be joined to fact data through _dkey

 

CREATE VIEW dim.System_Original AS

SELECT System_dkey, System

FROM   dim.System

WHERE System_pkey = 0          (System_key = System_dkey)

 

View provide historical dimension values and will be joined to fact data through _dkey

 

CREATE FUNCTION dim.System_Historical(@ReportTime datetime)

RETURNS TABLE AS RETURN (

SELECT System_dkey, System

FROM   dim.System

WHERE IsDeleted = 0 AND ValidFrom <= @ReportTime AND ValidTo > @ReportTime)

 

When dimension data have IsDeleted = 1 the value of _key is never used among fact data _key column therefore the registered view and historical view do not need to include the deleted dimension value and any­way the same dimension value exists already in the previous row in the dimension table with a ValidFrom/ValidTo period for the time when the value was current and active in the source legacy system.

 

An implementation in SSIS SQL Server Integration Services of type 7 dimension

 

 

Read how to implement the type 7 dimension ETL process in SSIS and how to load fact data with a transaction date

 

A dimension table will keep track of unknown values in the source legacy system

with an audit column which is a boolean (bit) with two values (1 = true and 0 = false):

 

  • IsInferred

IsInferred = 1 means that the row represent an unknown value from source system.

IsInferred = 0 means that the row represent a known value from source system.

 

An example

Lets have an example where the source legacy system has business key with null value and unknown values that does not exist in the dimension table:

 

System

_key

System

_dkey

System

_pkey

System

_bkey

System

ValidFrom

ValidTo

IsCurrent

IsDeleted

IsInferred

0

0

0

-

Missing

1900-01-01 00:00:00

9999-12-31 00:00:00

1

0

1

19

19

0

76CB

Warning

1900-01-01 00:00:00

2015-05-08 14:12:21

0

0

0

35

19

19

76CB

Notification

2015-05-08 14:12:21

2015-07-31 08:45:48

0

0

0

87

19

35

76CB

Caution

2015-07-31 08:45:48

9999-12-31 00:00:00.

1

0

0

88

88

0

88FF

Sign

1900-01-01 00:00:00

9999-12-31 00:00:00

1

0

0

 

Example of table SourceProduction with business key called SystemId:

 

OutageDate

SystemId

ProductionKWh

2015-05-25 10:22:43

76CB

173

2015-08-02 15:47:10

76CB

221

2015-08-12 22:21:42

88FF

100

2015-10-02 00:00:00

90AA

200

2015-10-12 00:00:00

90AA

300

2015-10-15 00:00:00

91KL

400

2015-02-07 00:00:00

NULL

500

 

All data rows in table SourceProduction will be loaded to table FactSystem where the business key SystemId will be transformed to the dimension key System_key in table DimSystem. There is three values in SystemId (90AA, 91KL, NULL) in four rows that does not exist in DimSystem, therefore they are inferred members and is infer to DimSystem where NULL will be transformed to System_key 0 for »Missing«, and 90AA and 91KL will be inserted into new data rows in DimSystem as »Unknown« with new numbers in System_key that will be used in loading data rows into FactSystem table.

 

After running the ETL process the table DimSystem will have new inferred rows:

 

System

_key

System

_dkey

System

_pkey

System

_bkey

System

ValidFrom

ValidTo

IsCurrent

IsDeleted

IsInferred

0

0

0

-

Missing

1900-01-01 00:00:00

9999-12-31 00:00:00

1

0

1

19

19

0

76CB

Warning

1900-01-01 00:00:00

2015-05-08 14:12:21

0

0

0

35

19

19

76CB

Notification

2015-05-08 14:12:21

2015-07-31 08:45:48

0

0

0

87

19

35

76CB

Caution

2015-07-31 08:45:48

9999-12-31 00:00:00

1

0

0

88

88

0

88FF

Sign

1900-01-01 00:00:00

9999-12-31 00:00:00

1

0

0

89

89

0

90AA

Unknown 90AA

1900-01-01 00:00:00

9999-12-31 00:00:00