Course contents 17 / 35

17 / 35 · Analytical Warehouses

Dimensional modeling

Choose a fact grain, join descriptive dimensions and decide which measures can be added across rows.

The sales dashboard asks how many orders, how many units and how much revenue the shop recorded. On the six order lines, those answers are 4, 10 and 4400 cents. One row supplies three different counts depending on what the measure represents.

Define the measurement event#

The grain states what one fact row represents. For the sales table it is one line of a completed order. In the toy dataset (order_id, line_no) distinguishes those events. A fact table stores rows at that grain with measurements and references to descriptive context. Its line amount records quantity times the price used in that sale. A refund is a different event unless the model explicitly defines a signed combined grain. (Kimball, 2008)

A dimension supplies context that we can use to filter and group. A product dimension can store name and category. A store dimension describes location, and a date dimension describes calendar periods. A star schema places the fact table in the centre and relates it directly to those dimensions. Each fact needs at most one matching row per relevant dimension key. Otherwise joining descriptions can duplicate the facts and inflate their measures. (Oracle, §2.4.1; Microsoft, Star schema)

Figure

A fact with three dimensions

A fact with three dimensionsDate, product and store dimensions connect to the central sales-line fact. The fact records quantity and amount in cents.DateStoreProductSales lineQuantityAmount
One fact row represents one completed order line. The dimensions describe its product, store and day.

The six lines give 1400 cents for tea, 1800 for coffee and 1200 for cocoa. Summing those subtotals gives 4400. Counting rows gives six positions. Counting distinct order IDs gives four orders because 101 and 103 each contain two positions. An order count grouped by product cannot be added across products when an order contains both tea and coffee.

Check what addition means#

Line amounts are additive across products or dates in this model, assuming the same currency, amount definition and disjoint fact rows. Unit price is a ratio-like measure. Adding the six unit prices answers no useful sales question. The price per unit across all lines is 4400/10=4404400/10=440 cents, obtained by summing the numerator and denominator first. Equal weighting of the six line prices would instead give 2650/62650/6, about 441.67 cents. Quantities differ, so the two averages differ. (Kimball, 2008)

A periodic snapshot records a measurement at regular times, with its own grain. For inventory, one row could be one store, product and closing day. If two successive snapshots show 9 and 7 tea units for a store, the second day’s closing stock is 7. The sum 16 has the interpretation of unit-days under this daily sampling convention. It is not the stock level. Stock can be additive across stores at a common instant and semi-additive across time. Put the sales events and inventory snapshots in separate facts and connect them through shared dimensions. (Kimball, 2008; Oracle, §2.4.1.1)

Next#

The product key tells us which row adds the category. If a product changes category, one key and one overwritten row can make yesterday’s sale appear in today’s category. History in a warehouse keeps the version that applies at the time of the event.

References#

  1. Ralph Kimball. Fact Tables. Kimball Group, 2008, on declared grain, additive measures and periodic snapshots.
  2. Oracle. Data Warehousing Logical Design. Oracle Database 19c Data Warehousing Guide, §2.4 on star schemas, facts and dimensions.
  3. Microsoft. Understand Star Schema and the Importance for Power BI. Product guidance on fact grain, dimensions and relationship direction.