By Rohit Ray · Independent educational lesson · Explore this visual lab

Module 13 · Lesson 3 of 11Detailed study · about 22 min

Facts, dimensions and the grain of a row

A fact records a measurable business event at a declared grain. A dimension describes the people, products or places used to interpret that event.

Understand the idea

If FACT_ORDER_LINE has one row per order/product line, an order with three lines must have three rows. Storing the full order total on every line and summing it would triple-count revenue. Declare the grain before choosing columns.

Key ideas in simple English
ConceptWhat it means
GrainExactly what one row represents.
FactAn event or measurement at that grain.
DimensionDescriptive context, possibly versioned over time.
Surrogate keyWarehouse-assigned identity independent of a source business key.

A concrete example

If FACT_ORDER_LINE has one row per order/product line, an order with three lines must have three rows. Storing the full order total on every line and summing it would triple-count revenue. Declare the grain before choosing columns.

Remember: Choose measures that are additive at the declared grain; preserve dimension version identity.

Explain it step by step · full theory

Understand the concept

If FACT_ORDER_LINE has one row per order/product line, an order with three lines must have three rows. Storing the full order total on every line and summing it would triple-count revenue. Declare the grain before choosing columns.

CUSTOMER_ID is a business key. A customer can have several historical city versions, each with its own dimension surrogate key. A fact needs the version valid when the event happened if the question is historical geography.

Apply it in practice

A sequence-generated surrogate key is convenient, but recreating every dimension key on each load can break fact relationships. Preserve the mapping. Standard Snowflake table PRIMARY KEY, UNIQUE and FOREIGN KEY declarations do not enforce these relationships for you.

The example below avoids dimension joins and demonstrates grain first. Later we join facts to half-open validity intervals. When a late dimension change alters an interval, already resolved fact keys may need controlled restatement.

Words used in this lesson
Grain
Exactly what one row represents.
Fact
An event or measurement at that grain.
Dimension
Descriptive context, possibly versioned over time.
Surrogate key
Warehouse-assigned identity independent of a source business key.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

Facts, dimensions and the grain of a row

Grain
Fact
Surrogate key

Understand the flow

A fact records a measurable business event at a declared grain. A dimension describes the people, products or places used to interpret that event.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Understand the flow

    A fact records a measurable business event at a declared grain. A dimension describes the people, products or places used to interpret that event.

  2. Apply the contract

    Choose measures that are additive at the declared grain; preserve dimension version identity.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual learning exercise. Production deployment needs source-specific contracts, access controls, orchestration and operational monitoring.

Facts, dimensions and the grain of a row — SQL example

Definition: A fact records a measurable business event at a declared grain. A dimension describes the people, products or places used to interpret that event.

When to use: Follow the isolated customer-history lab in lesson order.

Example: 3 order lines, 2 orders and revenue 90. Each measure has a clear meaning.

SQL · example
WITH lines(ORDER_ID,LINE_ID,AMOUNT) AS (SELECT * FROM VALUES (10,1,30),(10,2,20),(11,1,40)) SELECT COUNT(*) AS LINE_COUNT,COUNT(DISTINCT ORDER_ID) AS ORDERS,SUM(AMOUNT) AS REVENUE FROM lines;

What to expect and why

3 order lines, 2 orders and revenue 90. Each measure has a clear meaning.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Can you safely sum repeated order totals from every order line?

Try it yourself

Explain with the example: Can you safely sum repeated order totals from every order line?

Compare your reasoning

Choose measures that are additive at the declared grain; preserve dimension version identity.

Official sources and curriculum

Module 13 · See module scope