Skip to main content
Back to Academy🎟️ 1. Modern Analytical Foundations
5 min read
Try Hands-on Lab
VISUAL LESSON1. Modern Analytical Foundations

Two-Fact Dimensional Modeling: Inventory Listings vs. Transactional Sales

Master two-sided marketplace modeling (TICKIT, StubHub, Airbnb): separating Listing inventory supply from Sales settlements cleanly so you avoid Chasm Trap duplication.

Two-Fact Dimensional ModelingChasm Trap SQL PreventionListing vs Sales Fact TableTwo-Sided Marketplace SchemaMulti-Grain Analytics SQLConformed Dimensions Marketplace

Explain Like I'm New: Concert Ticket Ads vs. Real Checkouts

Think about any two-sided marketplace—like StubHub, Airbnb, or the TICKIT live-events warehouse: - Action 1 (Posting an Offer): A ticket seller posts 4 concert tickets (listing_id = 500, price = $100). Maybe 2 sell on Friday, 1 sells on Saturday, and 1 never sells! - Action 2 (Completed Sale): Two different buyers each purchase tickets from that listing across separate checkout transactions (sale_id = 9001 for 2 tickets, sale_id = 9002 for 1 ticket).

Beginners try to cram Listings AND Sales into a single table—or join fact_listing straight to fact_sales! Look what happens: listing_id = 500 listed 4 tickets (numtickets = 4). Joined directly to 2 sales rows (qtysold = 2 and qtysold = 1), `SUM(numtickets)` suddenly reads `4 + 4 = 8` tickets! Your marketplace thinks it has double the inventory it actually holds!

Key Beginner Takeaway: Two distinct business processes with different timelines and cardinalities (Supply Listings vs. Sales Settlements) MUST live in two separate Fact tables connected only through shared Conformed Dimensions (dim_event, dim_date, dim_user).

Key Terminology for Multi-Fact Marketplaces

Term / KeywordPlain-English MeaningMarketplace Example
Two-Fact ArchitectureTwo independent Fact tables representing Supply (fact_listings) and Demand (fact_sales).Tracks unsold seats *and* revenue cleanly without NULL-filled half-rows.
Chasm TrapJoining two 1-to-Many Fact tables directly through a shared parent key (listing_id or event_id).Silently multiplies metrics from whichever side repeats!
Drilling AcrossAggregating each Fact table separately to a shared Conformed Dimension (event_id), then joining those 1-row summaries!Combines Total Listed Tickets + Total Sold Tickets accurately.
Conformed DimensionShared dimension (dim_event, dim_date, dim_venue) used identically across both Facts.Guarantees "Rock Concerts" matches byte-for-byte across supply & demand teams.

Step-by-Step Worked Example: Safe "Drill Across" Pattern

Consider `fact_listing` and `fact_sales` for Event E10:

`fact_listing` (Supply)

listing_idevent_idseller_idnumtickets
L1E10U14
L2E10U22

True Supply for E10 = `6` listed tickets.

`fact_sales` (Demand)

sale_idlisting_idevent_idqty_soldtotal_paid
S1L1E102200.00
S2L1E101100.00
S3L2E102180.00

True Sales for E10 = `5` sold tickets, `$480.00` revenue.

Broken Query (Direct Join = Chasm Trap!)

-- WRONG: Joining listing -> sales clones L1 twice and L2 stays once (4 + 4 + 2 = 10!)
SELECT
  l.event_id,
  SUM(l.numtickets) AS inflated_listed,
  SUM(s.qty_sold)   AS sold
FROM fact_listing l
JOIN fact_sales s ON l.listing_id = s.listing_id
GROUP BY l.event_id;
-- Result: inflated_listed = 10 (67% WRONG!), sold = 5

Correct Query (Independent CTE Aggregation + `FULL OUTER` / `LEFT JOIN`) Aggregate Supply and Demand separately to **`event_id`** first, *then* join the two 1-row-per-event summaries!

WITH event_supply AS (
  SELECT
    event_id,
    COUNT(DISTINCT listing_id) AS listing_count,
    SUM(numtickets)            AS total_tickets_listed
  FROM fact_listing
  GROUP BY event_id
),
event_demand AS (
  SELECT
    event_id,
    COUNT(DISTINCT sale_id)    AS transaction_count,
    SUM(qty_sold)              AS total_tickets_sold,
    SUM(total_paid)            AS gross_merchandise_value
  FROM fact_sales
  GROUP BY event_id
)
SELECT
  e.event_id,
  e.event_name,
  COALESCE(sup.total_tickets_listed, 0) AS listed_tickets,
  COALESCE(dem.total_tickets_sold, 0)   AS sold_tickets,
  ROUND(
    COALESCE(dem.total_tickets_sold, 0) * 100.0 / NULLIF(sup.total_tickets_listed, 0),
    2
  ) AS sell_through_pct,
  COALESCE(dem.gross_merchandise_value, 0) AS gmv_usd
FROM dim_event e
LEFT JOIN event_supply sup ON e.event_id = sup.event_id
LEFT JOIN event_demand dem ON e.event_id = dem.event_id;

Output: listed_tickets = 6, sold_tickets = 5, sell_through_pct = 83.33%, gmv_usd = 480.00! Plus using LEFT JOIN from dim_event preserves events that received listings with 0 sales!


Common Beginner Mistakes (And How to Fix Them)

  1. Using `INNER JOIN` instead of `LEFT JOIN` from `dim_event`: Events with listed tickets that sold 0 seats disappear from conversion funnels, artificially raising reported sell-through to ~100%!
  2. Storing `buyer_id` columns on `fact_listing`: One listing of 6 tickets can be purchased by 3 different buyers over a week! Listings belong strictly to seller_id; Buyers belong strictly to fact_sales.
  3. Computing averages of ratios incorrectly: Never average per-listing sell_through_pct! Always sum total numerator / sum total denominator (SUM(sold) / NULLIF(SUM(listed), 0)).

Quick Cheat Sheet

  1. Separate Supply (`fact_listing`) and Demand (`fact_sales`) into independent Fact tables.
  2. Never JOIN two Fact tables directly—avoid the Chasm Trap!
  3. Pre-aggregate each Fact table in its own CTE to a shared Conformed Dimension grain before combining.
  4. Always wrap ratios with `NULLIF(..., 0)` and `COALESCE(..., 0)` so zero-sales events report 0% cleanly.

Comprehension & Architecture Check (3 Questions)

Test your understanding of the concepts covered in this lesson.

1. Why does joining an inventory listing table directly to a transaction sales table cause revenue distortion?
2. Why should beginners check a table's grain before writing a JOIN?
3. Which Medallion layer is meant to store clean, deduplicated, standardized records?
Practice What You Learned

TICKIT-01: Grain, Keys and the Two-Fact Model

TICKIT Marketplace connects event ticket sellers with buyers. A single ticket listing (like 10 tickets for a concert) can be bought across several different transactions (4 tickets to one person, 6 tickets to another). If you join listings directly to sales without pre-aggregating, the rows multiply (Cartesian fan-out) and reported revenue gets inflated by 300%. We need a query that aggregates each table separately before joining.

Solve Challenge