Can you explain what a fact table is and give an example?

Instruction: Define a fact table and provide an example scenario or data model where a fact table would be used.

Context: This question tests the candidate's understanding of data warehousing concepts, specifically the use and structure of fact tables in data analysis.

Updated

Official answer

A fact table records a business measurement or occurrence at a declared grain and links it to relevant dimensions. Some fact tables contain numeric measures; a factless fact table can instead record an occurrence, such as attendance, whose rows are counted.

For retail sales, define one row per order line. Columns might include order_id, line_number, product_key, customer_key, order_date_key, quantity, gross_line_amount, discount_amount and net_line_amount. Specify whether discounts are positive deductions and how tax, shipping and returns are represented.

Quantity and line amounts can often be summed across compatible rows. Unit price or a percentage should not simply be summed, and amounts in different currencies need a defined conversion policy. Repeating an order-level total on every line would inflate totals.

A transaction fact records events, a periodic snapshot records state at regular intervals, and an accumulating snapshot follows milestones in a process. These are different grains and should not be mixed casually. Test uniqueness at the chosen grain, dimension references, late corrections and reconciliation to the source.

Related Questions