SOURCES, FACTS AND DIMENSIONS

One star schema, five facts at a stated grain

Seven sources land in five fact tables. Each fact holds additive measures at exactly one grain; the dimensions hold the descriptions every report groups by. Pick a fact to see its grain, keys and sources.

Sources (nightly)
POS transactions and tendersstore database
Inventory by store and SKUstore on-hand snapshot
Transfersstore to store, DC to store
Receipts and purchase orderswith unit cost
Timecardshours by activity
Card processor settlementsdaily file
E-commerce ordersweb store as a store
Fact tables (grain)
Dimensions
DimProductSKU = style × colour × size; Department/DeptID, Class/ClassID, Vendor/VendorID
DimStoreStore/StoreID, region, format, open date, comp flag
DimCalendardate, retail week, 4-5-4 period, quarter, fiscal year, same day last year
DimEmployeeEmployee/EmployeeID, role, home store

factSales

Grain
One row per day × store × SKU
Measures
units, net sales, cost at sale, discount, tax, in-stock flag
Sources
POS transactions and tenders; E-commerce orders; Inventory by store and SKU
Dimensions
DimProduct, DimStore, DimCalendar
Rows a year
about 3.7 million
Used for
Every sales report, forecast and index. The in-stock flag comes from the opening on-hand.

DimCalendar: fiscal 2026 on the 4-5-4 pattern (52 weeks, 1 Feb 2026 to 30 Jan 2027)

The calendar dimension carries the retail week, period, quarter and fiscal year for every date, so "the same week last year" is a join, not a calculation in each report. The year ends on the Saturday nearest 31 January; periods run 4, 5 and 4 weeks in each quarter.

PeriodMonthWeeksRetail weeksStartsEnds
P01 (Q1)Feb41 to 41 Feb28 Feb
P02 (Q1)Mar55 to 91 Mar4 Apr
P03 (Q1)Apr410 to 135 Apr2 May
P04 (Q2)May414 to 173 May30 May
P05 (Q2)Jun518 to 2231 May4 Jul
P06 (Q2)Jul423 to 265 Jul1 Aug
P07 (Q3)Aug427 to 302 Aug29 Aug
P08 (Q3)Sep531 to 3530 Aug3 Oct
P09 (Q3)Oct436 to 394 Oct31 Oct
P10 (Q4)Nov440 to 431 Nov28 Nov
P11 (Q4)Dec544 to 4829 Nov2 Jan
P12 (Q4)Jan449 to 523 Jan30 Jan

The scorecard nights below fall in retail weeks 40 to 43; 28 Nov is the last day of week 43. Same day last year = date minus 364 days, so a Saturday compares with a Saturday.

CYBEX CONVENTIONS, BY FUNCTION

Five conventions that keep the data testable

None of these is clever. Each one removes a way for two reports, two databases or two app versions to disagree.

01 · Nightly ETL

From the store databases into the facts, every night

After the stores close, the load copies each store's transactions, tenders, stock moves and timecards into staging, checks them against the store's control totals and writes the facts. It reloads a trailing window of 8 days so late corrections land.

Each store-day is written delete-then-insert, so running a step twice cannot duplicate it. The bad night in the scorecard is what happens when a step is re-run by hand without that.

02 · BI reads facts only

Views read the fact tables, never the transactional tables

A BI view that needs a missing column gets it from the load: the column is added to the fact, then passed through. A view never joins back to the live order tables.

This keeps every report on one grain and one set of tested numbers, and keeps heavy queries off the store systems.

03 · Naming

The bare name is the description; the code is name + ID

Department holds "Outerwear", DeptID holds "410". The same rule everywhere means a report writer never has to guess which column to group by and which to join on.

Description columnCode column
Department: OuterwearDeptID: 410
Class: HoodiesClassID: 4120
Vendor: Kelpmoor KnitsVendorID: NWK
Store: HollinbyStoreID: S-108
04 · Versioned deployment

A database is always at a known module version

Apps never change the database. Each module ships as one cumulative, re-runnable deployment script per version, with a rollback. The script checks prerequisites, refuses to downgrade, and writes every run to a deployment log.

Run StoreFacts_1.3.0_Deploy.sql. It reads 1.1.0 from the deployment log and applies the guarded upgrade steps for 1.2.0 and 1.3.0 in the same run (no older script first), then logs Deployed 1.1.0 to 1.3.0.
05 · HQ copy and cloud copy

Two copies, compared every night

Head office keeps the working copy; a cloud copy serves remote users and BI pages. After the load, a sync check compares row counts and sums per table per day, and a difference stops the cloud refresh instead of publishing it.

Sat 28 Nov: 16,113 POS lines and $610,292.99 of net sales in both copies; 5 facts and 4 dimensions compared.

Deployment log

What the log shows for one module

Every run is a row: Started, then Deployed, Failed or Blocked. Support reads the log before reading any code.

DateCopyFromToStatus
14 Sep 2026HQ1.0.01.1.0Deployed
19 Oct 2026HQ1.1.01.2.0Deployed
19 Oct 2026Cloud1.1.01.2.0Failed
20 Oct 2026Cloud1.1.01.2.0Deployed
16 Nov 2026HQ1.2.01.3.0Deployed
16 Nov 2026Cloud1.4.01.3.0Blocked
DATA QUALITY AS STATISTICS

A nightly scorecard with control limits

Seven checks per store-day: complete, on time, unique keys, keys found in the dimensions, sales equal tenders, stock rolls forward, card payments cleared. A check that cannot run counts as failed. Each measure has its own control chart, so a bad night stands out against normal night-to-night noise.

Quality score: store-day checks passed. Centre 99.2%, lower limit about 97.1% (it moves with each night's n), from nights 1 to 20. Baseline nights dropped and refit: 19 Nov. Nights outside: 19 Nov (94.6%), 23 Nov (90.5%).
or click a point on the chart
MeasureValueCentreLimitStatus
Quality score90.5%99.2%97.1%Outside
Completeness97.34%99.97%99.89%Outside
Mean ETL lag3.55 h3.28 h3.78 hWithin
Duplicate keys1,3040.201.54Outside
Orphan keys280.211.59Outside
Out of balance30.352.11Outside
Roll-forward96.55%99.85%99.80%Outside
Cleared rate96.88%99.59%99.25%Outside
FAILED STORE-DAY CHECKS

Mon 23 Nov: 16 of 168 checks failed. Root cause logged next morning: Three faults at once: the S-117 store database did not arrive (network); the sales step was re-run by hand for S-104 and S-109 without delete-then-insert; a new style sold before the product dimension was refreshed.

  • S-102 Brackenford · Keys found
    7 rows with a SKU not in the product dimension
  • S-104 Dovecrest · Unique keys
    678 duplicate keys
  • S-104 Dovecrest · Sales = tenders
    sales incl. tax minus tenders = $36,874.23
  • S-106 Fernwold · Keys found
    7 rows with a SKU not in the product dimension
  • S-107 Gorsebank · Unique keys
    1 duplicate keys
  • S-109 Ivelmere · Unique keys
    625 duplicate keys
  • S-109 Ivelmere · Sales = tenders
    sales incl. tax minus tenders = $35,480.79
  • S-111 Kestrelton · Keys found
    7 rows with a SKU not in the product dimension
  • S-117 Quillbury · Complete
    0 of 258 POS lines landed
  • S-117 Quillbury · On time
    landed 13.6 h after close (limit 7 h)
  • S-117 Quillbury · Unique keys
    could not run: no data at check time
  • S-117 Quillbury · Keys found
    could not run: no data at check time
  • S-117 Quillbury · Sales = tenders
    could not run: no data at check time
  • S-117 Quillbury · Roll-forward
    could not run: no data at check time
  • S-117 Quillbury · Card cleared
    could not run: no data at check time
  • S-120 Tansymead · Keys found
    7 rows with a SKU not in the product dimension
RECONCILIATIONS

Three tie-outs against independent sources

A check against the same table proves little. These three compare the facts with something recorded separately: the tenders taken, the store's own on-hand count, and the processor's settlement file.

1. Sales equal tenders, per store-day

Net sales plus tax in the sales fact must equal the tender lines in payments, within $1.00. The right-hand store-day is from the bad night: its sales were loaded twice, its tenders once.

S-101 Alderwick, Sat 28 Nov: balanced
LineAmount
Net sales (sales fact)$37,663.17
Tax (sales fact)$4,896.21
Sales incl. tax$42,559.38
Tender: Cash$5,958.31
Tender: Debit$10,214.25
Tender: Credit$22,130.88
Tender: Gift card$2,553.56
Tender: Store credit$1,702.38
Tenders total (payments)$42,559.38
Difference$0.00 Balanced
S-104 Dovecrest, Mon 23 Nov: sales loaded twice
LineAmount
Net sales (sales fact)$65,264.12
Tax (sales fact)$8,484.34
Sales incl. tax$73,748.46
Tender: Cash$5,162.39
Tender: Debit$8,849.82
Tender: Credit$19,174.60
Tender: Gift card$2,212.45
Tender: Store credit$1,474.97
Tenders total (payments)$36,874.23
Difference$36,874.23 Out of balance
Over 28 nights, 13 of 672 store-days failed this check (1.93%): 2 from the duplicated sales step, 9 from tenders keyed wrong at the till (manual tender, wrong card type), and 2 that could not run because the store's data had not landed.

2. Stock ledger roll-forward at moving-average cost

Fleece hoodie, navy, size M at S-108, retail weeks 38 to 43. The closing units computed from the stock moves are compared with the store's own on-hand snapshot, an independent source. Receipts update the moving-average cost; sales, transfers and adjustments move at the current average.

Closing = Opening + Receipts - Sales + Transfers in - Transfers out ± Adjustments · Avg cost after a receipt = (units × avg + received × cost) / (units + received)
Week (ending)OpenReceipts @ costSalesTfr inTfr outAdjClosingStore on handDiffAvg costClosing value
Wk 38 (24 Oct)2436 @ $18.901400046460$18.70$860.20
Wk 39 (31 Oct)4601740-132320$18.70$598.40
Wk 40 (7 Nov)3224 @ $19.601906031310$19.09$591.66
Wk 41 (14 Nov)3101506010100$19.09$190.86
Wk 42 (21 Nov)1030 @ $19.202320-217170$19.17$325.91
Wk 43 (28 Nov)17012000550$19.17$95.86
All 6 weeks roll forward: the closing units equal the store's own on-hand every week, and the value identity holds to within $0.00. Closing at Wk 43: 5 units × $19.17 moving-average cost = $95.86.

3. Card payments against processor settlements

Each POS card payment is matched to the processor's settlement record in passes: by invoice, then by authorization code, then as a split tender. What is left is an exception for the sales audit queue. The Cleared rate is cleared items over all card items, POS and processor side.

Matched by invoice
111,034 · 96.33%
Matched by authorization code
2,888 · 2.51%
Matched as split tender
687 · 0.60%
Amount mismatch
129 · 0.11%
POS only (no settlement)
198 · 0.17%
Processor only (no POS payment)
329 · 0.29%
Cleared rate 99.43%: 114,609 of 115,265 card items over 28 nights (bar length is the square root of the count, so the small exception rows stay visible). 178 of the 329 processor-only items belong to store-days whose POS data had not landed; they clear on the next night's run. The other 478 are real exceptions for the sales audit queue.
CENSORED DEMAND

Sales are not demand when the shelf is empty

One SKU at one store, simulated so the true demand is known: Poisson demand at 3.00 units a day times the day-of-week index, a delivery every Monday up to the order-up-to level, 84 days. Days that open empty record zero sales whatever the demand was; days that sell out record less than it. Flagging in-stock days removes the empty days; the censored likelihood also handles the days that sold out part way.

True demand rate
3.00 / day
Set in the simulation; mean daily demand 3.01 this run
Naive: mean of sales
2.31 / day
-23.0% against the true rate: every empty day counts as zero demand
In-stock days only
2.82 / day
-5.9%: 13 days that opened empty left out, DOW-adjusted
Censored likelihood
3.06 / day
+2.1%; 95% interval 2.62 to 3.50
Seed 11, order-up-to 16 units, delivery every Monday: 13 of 84 days opened empty and 10 more sold out during the day. Lost sales: 59 units in truth, 63 estimated from the censored likelihood. Over 200 runs at this level the naive mean is off by -23.9% on average, in-stock days by -8.5%, the censored likelihood by +0.4%.
Estimator (200 seeded runs)Mean errorRMSE
Naive: mean of all daily sales-23.9%23.9%
In-stock days only, DOW-adjusted-8.5%10.1%
Censored Poisson likelihood+0.4%7.0%
95% interval covers the true rate97.0%of runs
FEATURES FOR PAGES 01 TO 05

Six features and the table each comes from

The models on the other pages do not read raw sales. They read features built once, in the platform, from the facts above. Worked examples use the stated inputs.

Pages 01, 02 · Stock cover

Weeks of supply (WOS)

Base = (W1 + .. + W6) / weeks in stock / mean SI of W1..W6 · WOS = On hand / (Base × forward SI)

Six complete weeks only (never the week in progress), divided by the weeks the item was actually in stock, de-seasonalized.

From factSales, factStockLedger, seasonal index · grain SKU or style-colour × store × week
6.8 weeks
Base = 223 / 6 / 1.08 = 34.4 a week; forward 34.4 × 0.92 = 31.7; WOS = 214 / 31.7 = 6.8
Pages 02, 03 · Buying

Sell-through

Sell-through = Units sold / (Opening on hand + Units received)

Over a stated period. A ratio of sums, computed in the report from additive ledger measures, never averaged across stores.

From factStockLedger (opening, receipts, sales) · grain style-colour × store × period
68.7%
412 sold / (0 opening + 600 received) = 68.7%
Pages 01, 02, 03 · Size curve

Size index

Size index = Size share of units × number of sizes (mean 1), from store-weeks with every size in stock

Shares from broken size runs understate the core sizes, the same censoring as below. The table compares both.

From factSales + in-stock flag, DimProduct (size) · grain size × class or style
SizeFull runIndexAll weeksIndex
S520.80610.94
M961.48881.35
L811.25721.11
XL310.48390.60
Size M: 1.48 from full runs against 1.35 from all weeks; the all-week index would under-buy the core size by 8%.
Pages 01, 03, 04 · Store split

Site index, shrunk toward 1

Raw = store weekly units / mean store weekly units · Shrunk = (n × Raw + k × 1) / (n + k)

n = weeks of history, k = weeks of prior weight. A new store's index starts near 1 and earns its own value as weeks accrue.

From factSales, DimStore · grain store × class
StoreWeeks (n)RawShrunk
S-104521.321.28
S-112520.860.88
S-12461.701.30
Page 02 · Seasonality

Seasonal index (SI)

SI_w = de-censored units in week w / mean weekly units of that year, averaged over years (mean 1 over 52 weeks)

Built on the 4-5-4 week so years line up; stockout weeks are de-censored before they enter the index.

From factSales, DimCalendar (retail week) · grain class × retail week
SI = 1.52
Retail week 47 (ending 26 Dec): 1,840 / 1,215 = 1.514; 1,920 / 1,262 = 1.521; mean 1.52
Pages 02, 04 · Daily split

Day-of-week index (DOW)

DOW_d = mean sales on weekday d / mean of the seven weekday means (mean 1)

Estimated here from the chain's nightly sales fact, leaving out nights the scorecard flagged.

From factSales, DimCalendar · grain chain or store × weekday
DayNightsEstimatedSet in simulation
Sun41.091.10
Mon30.780.78
Tue40.820.80
Wed40.850.86
Thu30.970.96
Fri41.181.18
Sat41.311.32
26 of 28 nights used (flagged nights left out); largest gap to the simulated index 0.02.
DATA FLOW

From the store databases to tested features

Three layers: sources, the platform that loads and tests them, and the models and apps that read only what passed.

Layer 1 · Sources
Store databasesPOS, tenders, stock, transfers, receipts, timecards
Card processorsettlement file, daily
Web storee-commerce orders and payments
Head officeproduct, POs, plans
Layer 2 · Data platform
Nightly ETLstaging, control totals, delete-then-insert
Facts and dimensionsfive facts, one grain each
Scorecard and tie-outscontrol charts, three reconciliations
HQ and cloud copiessync check, versioned scripts
Layer 3 · Features, models and apps
FeaturesWOS, sell-through, size, site, SI, DOW
Models on pages 01 to 05BOM stock, forecasting, assortment, store ops, sales audit
BI insight pagesread the facts only
Apps on page 07distribution, PO workbench

Feedback: every exception that a person resolves becomes a test case for the next night's checks.

State the grain

One grain per fact, additive measures only. Most "the numbers don't match" questions are two grains being compared.

Test the load like a process

Control limits separate a bad night from normal noise, so people stop chasing noise and do not miss the bad night.

Reconcile to something independent

Tenders, the store's own count and the processor file each catch errors that a check on the same table cannot.

Flag in-stock days

Without the flag every forecast learns the stockouts as low demand and repeats them.