Keep order lines and returns at a declared grain
One order has three lines and two returns. Joining both child tables on order ID yields six rows. How can the warehouse report sales and returns accurately?
Keep order lines and returns at a declared grain
A fact records something measurable at one declared grain. A dimension gives it context. Two independent fact tables can share a date or customer dimension without joining raw child rows together. Test the design on a case with multiple items on both sides.
In the recording
Model a trip as a fact with rider, city and vehicle dimensions and weigh the extra joins from normalizing a dimension.
Work through the decision
One order has three lines and two returns. Joining both child tables on order ID yields six rows. How can the warehouse report sales and returns accurately?
Check your reasoning
Declare a row per line and a row per return. Aggregate each fact to the intended reporting grain before joining, or relate each through conformed dimensions. A join that preserves counts on a sample with one child per order can still multiply real data.
Decisions and tradeoffs
- Fact grain
- Write down the event represented by one row. Validate its unique key before joining or aggregating.
- Conformed dimension
- Use consistent customer or product identifiers and attributes across fact tables so reports can group comparable events.
- Pre-aggregation
- Roll each child table up to the join key before combining independent one-to-many relationships.
- Denormalization
- Keep frequently used related attributes together or use nested fields when the read pattern benefits. Consider update complexity and repetition.
Practice the guide skills
- Draw facts and dimensions for a refund and its original sale.
- Compare a star and a normalized dimension for query and update costs.
- Define the business metric and the time it is recognized.
- Check a real query plan against expected join cardinality.
Official objectives for this lesson
Related lesson · Define a measure once and share the right dashboard
Keep order lines and returns at a declared grain quiz
Answer 3 questions. Check each answer for an explanation.