The JOIN worked. The numbers quietly multiplied.
Dimensional modeling starts with grain, not with a star schema that happens to look nice.
Correct syntax does not mean the answer is right.
The orders table contains O-01 for Rp100,000 and O-02 for Rp80,000. The items table has two items for O-01 and one for O-02. Joining on order_id produces three rows. Sum order_total after that join and the total becomes Rp280,000 because O-01 appears twice. The database followed your instruction correctly. The aggregation meaning was wrong.
Kimball puts the grain declaration at the foundation of dimensional design. Write down what one row means. Do not mix orders and items into one measure without a clear transformation. A fact table is not just a table with lots of numbers.
Facts record events. Dimensions provide context.
fact_order_items can store item quantity and value. A product dimension describes category. A customer dimension describes segments. A date dimension supports time analysis. The joining keys need to stay consistent. A phone number does not become a metric just because it contains digits. Measure definitions follow the business process, not the column type.
If the question is the number of orders, use order identity or a model at order grain. If the question is product units, use item grain. Both can exist side by side if their names, documentation, and aggregation rules are clear. A model helps consumers answer questions. It should not force every question into one giant table.
Time is part of the model too.
Sales per transaction differs from an end-of-day balance and from fulfillment duration. Summing the same account balance across days usually does not answer a question about balance. Before choosing a fact structure, write down example questions it needs to support. The grain decision affects which questions can be answered without guessing.
Consider a product changing category or a customer changing segment. Should history use the attribute as it was at purchase time or the latest attribute? Both can be valid, but they produce different results. If a dimension has multiple versions, make the temporal relationship explicit. Joining only on customer_id can duplicate transactions.
Test cardinality before decorating the chart.
Count unique keys on both sides and state the expected relationship: one-to-one, many-to-one, or many-to-many. After the join, compare fact identities and totals that should stay stable. Add examples with multiple items and multiple dimension versions. The happy path of one order with one item often hides fanout.
The answer is not automatically SELECT DISTINCT. Two valid orders can have the same amount. SUM(DISTINCT order_total) can remove one of them. Aggregate details to the grain you need, or calculate from the fact that owns the measure. DISTINCT can sweep away the symptom while discarding a valid event.
Make the correct path the easy path.
Give models names that explain their grain, include example queries, and document measures safe to aggregate. Test the joins people use most often. The more consumers a model has, the more important it is to reduce room for misinterpretation. A screenshot of a diagram is not much help to someone writing a query before a meeting.
In a review, ask the author to show one case where the model would multiply a value if used incorrectly. A model that can demonstrate and prevent that mistake provides real value. Performance is not only query milliseconds. The team's time spent investigating wrong numbers is also a system cost.
An example to inspect.
-- Aggregate details to order grain
WITH per_order AS (
SELECT order_id, SUM(item_amount) AS item_total
FROM order_items GROUP BY order_id
)
SELECT SUM(item_total) FROM per_order;
-- Do not sum a header total after a 1:N join without controls.
Why is SUM(DISTINCT order_total) not a general fix for fanout?
Two different orders can have the same amount. DISTINCT on the amount removes one. Use grain and identity, not amount uniqueness.
Keep these three things.
- Declare the grain of every fact.
- Test cardinality and dimension versions.
- Reconcile keys and measures before and after joins.
Sources, not slogans.
Primary references reviewed on 7 November 2026. The explanation, examples, and visual were prepared by RapiApp. The diagram simplifies the topic for learning. The article explains its assumptions and limits.
- Kimball: Grain
- Kimball: Fact Tables
Continue the foundations.
- The JOIN worked. The numbers quietly multiplied.
- Conversion 50% or 82.7%? Both are showing up in the meeting.
- All tests are green. Why is the report still wrong?