Skip to main content
Quanta Meridian logo

All examplesExample 1 of 15

Reporting FoundationsExample 1 of 3 in this collection

Reporting Foundations

Wholesale Sales, Margin and Stock Reporting Mart

A reporting analyst prepares the wholesaler’s May sales, margin and stock report from invoice lines, supplier orders and warehouse movements, with each figure checked before finance, sales and warehouse managers use it.

Wholesale records converging on the May 2016 reportInvoice lines, purchase order lines and stock movements pass through shared reporting definitions and eighteen checks before the May 2016 report is released.SALES INVOICE LINESPURCHASE ORDER LINESWAREHOUSE MOVEMENTS228,2658,367236,667MAY 2016 REPORT£4,970,93349.15% gross margin18 CHECKS · READYMANAGEMENT REVIEWRelease reportor inspect a record
  1. 01228,265 invoice lines
  2. 028,367 purchase order lines
  3. 03236,667 stock movements
  4. 0418 checks passed
  5. 05May 2016 report ready
Executed DuckDB results · Microsoft Wide World Importers · January 2013 to May 2016

A wholesale month end

Can the wholesaler's monthly sales and stock report be released?

A sales manager and finance partner can receive plausible but different margin totals when invoice lines, supplier orders and stock movements use different joins, dates or product references. The reporting analyst must settle those definitions before the May report is used.

This project builds one SQL reporting foundation from those records. It gives the analyst a clear choice: publish the checked May 2016 report, or hold any failing record with its original key and reason for investigation.

Invoice lines
228,265
Business months
41
Stock movements
236,667
Report checks
18 passed

Primary retained evidence

The executed result shows the report row and the controls that permit release.

This view is generated from the retained DuckDB outputs after the clean build. It is an evidence render, not a database-client screenshot; the executable SQL and its ordered build stages remain inspectable below.

DuckDB query output · May 2016

The same retained files provide 6,351 invoice lines, £4,970,933 net sales, 49.15% gross margin and 18 passing report checks. Open the evidence viewer for the full-resolution result; the mobile source uses a dedicated readable composition.

The May 2016 management view

What sold, what margin it produced and whether stock needs attention.

The retained SQL tables include the monthly commercial report and product margin report. Finance can review the movement in net sales and margin while sales and warehouse managers can identify products whose value, margin and stock position warrant a closer look.

Monthly commercial reportNet sales and gross margin across 41 retained months.
01/1301/1401/1501/1605/16£4,970,933 net sales49.15% gross marginNet salesGross margin %
Product margin matrixTop retained products by net sales, with margin and current stock.
ProductNet salesMarginStock
Air cushion machine (Blue)£11,107,25140.0%12,530
32 mm Anti static bubble wrap (Blue) 50m£6,384,00055.2%103,958
10 mm Anti static bubble wrap (Blue) 50m£6,329,07054.5%308,519
20 mm Double sided bubble wrap 50m£6,214,32085.2%188,962
32 mm Double sided bubble wrap 50m£6,190,24047.3%68,906
10 mm Double sided bubble wrap 50m£5,943,00046.7%26,193
20 mm Anti static bubble wrap (Blue) 50m£5,795,64046.1%274,265
32 mm Anti static bubble wrap (Blue) 20m£2,900,16052.1%291,347

What management should notice

Sales recovered in May, while product mix still deserves scrutiny.

These observations are calculated from the retained monthly and product reports. They identify where to investigate; they do not claim a cause that the invoice and stock records cannot prove.

  1. 01+8.9% net sales

    May reached £4,970,933, up from £4,563,666 in April and +10.9% against May 2015.

  2. 02+0.36 points margin

    Gross margin recovered to 49.15% after April, but remained 0.41 points below May 2015. Finance can separate a sales recovery from a margin recovery.

  3. 0329.5% in eight products

    The eight largest products produced almost three tenths of retained net sales. Air cushion machine (Blue) alone contributed 6.4%, but its 39.97% margin was 9.80 points below the overall product mix.

Three event streams

The analyst sees invoice lines, supplier orders and warehouse movements separately.

The monthly pack does not flatten the wholesaler's records into one vague table. Each stream keeps its own business meaning, then joins through shared customer, product, supplier, warehouse and date definitions.

01

Invoice lines

One posted sales invoice line

228,265Sales.InvoiceLines

Feeds net sales, gross profit and product margin.

02

Purchase order lines

One ordered supplier item

8,367Purchasing.PurchaseOrderLines

Shows purchasing commitments beside stock and sales demand.

03

Stock movements

One warehouse movement event

236,667Warehouse.StockItemTransactions

Explains whether the month-end stock picture agrees with product movement.

How the records become a report

Three operational streams converge on one set of reporting definitions.

Each fact table has a declared grain: one posted invoice line, one purchase order line or one stock movement. Shared dimensions make sure a product or customer means the same thing wherever it appears.

Wholesale reporting mart lineageSales, purchasing and warehouse records pass through staging checks into shared dimensions and three fact tables. Valid rows feed commercial reports while failed rows remain in an exception table.SALES ORDERS + INVOICESPURCHASE ORDERSSTOCK MOVEMENTSRAW + STAGINGinvoice-line checkssupplier + product checksmovement + date checksSHARED DIMENSIONSDATECUSTOMERPRODUCTSUPPLIERWAREHOUSESALESPERSONFACT SALESone posted invoice lineFACT PURCHASINGone purchase order lineFACT STOCKone movement eventEXCLUDED ROWSreason · owner · record keyMONTHLY SALES + MARGINPRODUCT + STOCK REVIEWPURCHASING COMMITMENTS
  1. 01
    Operational records

    Sales invoices, purchase orders and warehouse stock movements arrive at their own level of detail.

  2. 02
    Checks before reporting

    Business keys, references, dates and values are tested. Failed rows keep their reason and original key.

  3. 03
    Shared dimensions and facts

    Every report uses the same customers, products, suppliers, warehouses, salespeople and dates.

  4. 04
    Monthly review

    Sales, margin, purchasing and stock outputs are released only after all 18 checks pass.

The reporting tables cover 2013-01-01 to 2016-05-31. Sales and margin come from invoice lines, purchasing commitments come from order lines, and warehouse movement remains a separate event fact.

The selected Microsoft records all passed the release rules. Nine deliberately broken fixture records prove that duplicate, missing-reference, date, cancellation, credit and value-mismatch cases are detected without being mixed into Microsoft's sample data.

The SQL that builds the monthly report

Read the calculation, rerun it and compare the result with the invoice records.

The monthly table counts invoice lines, adds net sales and gross profit, then keeps purchase order and stock movement totals at their own meaningful level. DuckDB makes the example portable; it does not imply a live cloud platform or production scheduler.

50_build_marts.sqlExecuted in the verified build
CREATE TABLE mart.monthly_commercial_report AS
WITH months AS (
  SELECT DISTINCT month_start
  FROM conformed.dim_date
),
sales AS (
  SELECT
    date.month_start,
    COUNT(*) AS invoice_lines,
    COUNT(DISTINCT invoice_id) AS invoices,
    SUM(quantity) AS units_sold,
    SUM(net_sales_value) AS net_sales_value,
    SUM(line_profit) AS gross_profit,
    SUM(extended_price) AS invoice_value
  FROM conformed.fact_sales sale
  JOIN conformed.dim_date date ON sale.invoice_date_key = date.date_key
  GROUP BY date.month_start
),
purchasing AS (
  SELECT
    date.month_start,
    COUNT(*) AS purchase_order_lines,
    SUM(expected_order_value) AS expected_purchase_value
  FROM conformed.fact_purchasing purchase
  JOIN conformed.dim_date date ON purchase.order_date_key = date.date_key
  GROUP BY date.month_start
),
stock AS (
  SELECT
    date.month_start,
    COUNT(*) AS stock_movements,
    SUM(quantity) AS net_stock_movement
  FROM conformed.fact_stock_movement movement
  JOIN conformed.dim_date date ON movement.transaction_date_key = date.date_key
  GROUP BY date.month_start
)
SELECT
  months.month_start,

Eight ordered files create the schemas, load the Microsoft records, build the reporting tables and stop the release when a check fails.

  1. 0100_create_schemas.sql

    Creates raw, staging, conformed, mart and audit schemas before any reporting table is built.

  2. 0210_load_raw.sql

    Loads the selected Wide World Importers tables without changing the Microsoft business values.

  3. 0320_stage_sources.sql

    Joins operational headers to their lines, types the fields and records failures before the reporting tables are released.

  4. 0430_build_dimensions.sql

    Creates shared date, customer, product, supplier, warehouse and salesperson dimensions.

  5. 0540_build_facts.sql

    Builds one sales row per posted invoice line, one purchasing row per order line and one stock movement per event.

  6. 0650_build_marts.sql

    Produces the monthly commercial report, product margin view and current stock position.

  7. 0760_run_tests.sql

    Checks keys, dates, references, row counts and invoice, purchase and stock values before release.

  8. 0870_build_trace_and_release.sql

    Retains the six-step invoice-line trace and records whether the monthly report is ready.

One invoice line, start to finish

InvoiceLineID 1 stays visible from the invoice table to the monthly sales figure.

The trace is generated by the build. It is not a narrative example typed into the website after the fact.

  1. 01
    Original invoice lineSales.InvoiceLines

    Invoice 1 · stock item 67 · quantity 10 · invoice value £2,645

    The original Microsoft row is retained without business rewriting.

  2. 02
    Staging joinstaging.sales_line_quality

    Customer 832 · order 1 · invoice date 1 January 2013

    The line is joined to its invoice and sales order, and its dates and references are checked.

  3. 03
    Conformed keysconformed dimensions

    Customer key 434 · product key 67 · salesperson key 1

    Stable reporting keys connect the line to the same customer, product, salesperson and date used by every report.

  4. 04
    Sales factconformed.fact_sales

    Net sales £2,300 · gross profit £850

    The published fact keeps one row per posted invoice line.

  5. 05
    Validationaudit.validation_results

    18 of 18 checks passed

    Count, key, relationship, date and value checks must pass before release.

  6. 06
    Report measuremart.monthly_commercial_report

    Revenue measure = SUM(fact_sales[net_sales_value]) · month 1 January 2013

    The line contributes once to the retained monthly sales result and to the documented downstream DAX measure.

Before the report is released

Counts, relationships and values must all reconcile.

The SQL build stops if a control fails. A second clean rebuild then compares the row counts, financial totals and reproducibility fingerprint so the same inputs cannot quietly produce a different result.

CheckResultOwnerWhy it matters
Invoice-line source scalePassData engineerThe selected official source must exceed the publication threshold.
Invoice-line business key is uniquePassFinance systems analystOne source invoice line can contribute at most once.
Invoice value reconciles to fact and held rowsPassFinance business partnerThe invoice value bridge must balance to one penny.
Purchase-order lines reconcile to factPassPurchasing analystEvery valid purchase line enters the purchasing fact once.
Stock movements reconcile to factPassWarehouse managerEvery valid movement enters the stock fact once.
Monthly sales mart ties to sales factPassFinance business partnerThe monthly report retains the complete net sales value.

The retained validation file contains all 18 checks, including 6 release controls highlighted here.

Release reconciliation · May 2016

The analyst can explain the published month and the records kept out.

The May 2016 mart contains 6,351 invoice lines and £4,970,933 of net sales. Gross margin is 49.15%.

Purchasing contributes 210 order lines, while the warehouse view retains 6,562 movement events. Finance, sales and warehouse managers can compare those outputs without flattening them into one ambiguous table.

Net sales
£4,970,933
Gross profit
£2,443,449
Invoice lines excluded
0
Publish or hold
READY
Measured228,265

posted invoice lines across the retained Microsoft sample.

Accepted228,265

invoice lines enter the sales fact once after the checks pass.

Excluded0

official invoice lines are kept out of the report in this build.

Proved separately9

broken fixture rows are rejected before they can affect a report.

Data and limits

Built from Microsoft's public wholesale sample and verified by 18 controls.

  • Wide World Importers is a public Microsoft sample, not a client system or a current trading company.
  • The local DuckDB build demonstrates modelling and controls, not production security, orchestration or operational scale.
  • The selected Microsoft records produce no open exceptions, so nine deliberately broken records are tested in a separate fixture and never enter the reporting facts.
  • A separate T-SQL deployment package is retained and linted, but it is not presented as executed SQL Server evidence.
Technical detailsView the data, rebuild steps and detailed limits
npm run verify:sql-foundation

The command verifies Microsoft's BACPAC checksum, extracts the selected tables, runs all eight SQL stages, exports the results and performs a second clean rebuild. The retained result fingerprint is 47ea77cb3db30d65821907bb622a48a1.

The data comes from Microsoft's Wide World Importers public sample, release wide-world-importers-v1.0, under the Microsoft SQL Server samples MIT licence.

More examples in Foundations

Invoice INV-000004 comparison showing an £81 invoice price against the £75 approved order price, 11 accepted units, unchanged bank details, approved price-change support, independent rematch and approval to enter a separate payment process; no payment was executed

Multi-site wholesale Accounts Payable

Supplier Invoice Matching and Review

Accounts Payable receives the supplier invoice, Procurement holds the approved order and the warehouse records what arrived. The contained reviewer workflow preserves every question, response, rematch and final decision.

What it helps answer: Should the invoice enter the separate authorised payment process, remain held or be returned to the supplier?

Platform
DuckDB, SQL, Python and Parquet with a contained reviewer report
Data scale
2,075 invoice review cases, 8,303 workflow events and 2,081 match attempts, verified
Project status
Built and checked with SQL and Python. All 27 controls and 19 tests pass, and a clean rebuild produces the same outputs.
View Supplier Invoice Matching and Review

Next step

Make the next monthly report explainable and repeatable.

Start with the files, joins and checks that make the current report difficult to explain or maintain.