Behind every reliable dashboard is a well-designed data model: the tables and the relationships between them. If the model is wrong, even a beautiful chart shows wrong numbers.

Why Model the Data

Real data come from many sources: sales, products, customers and dates. A single flat table repeats information (the product name on every sale row), wastes space and is hard to keep consistent. A model stores each fact once and links the tables, so that the tool can filter and aggregate correctly across them, load faster and be maintained easily.

The Star Schema

The best-practice design is the star schema. A central fact table holds the events and numbers (each sale with quantity and amount) and foreign keys. Around it are dimension tables that describe the context: Product, Customer, Date and Region. The fact table is the "many" side and each dimension the "one" side of a one-to-many relationship, so the diagram looks like a star. A snowflake schema normalises the dimensions further.

Relationships, Keys and Filter Direction

Tables are linked through a key column: the dimension has a unique primary key (ProductID) and the fact table holds the matching foreign key. The cardinality (one-to-many, one-to-one, many-to-many) tells how rows match. In Power BI, a filter flows from the "one" side to the "many" side: choosing a product category in a slicer filters the Sales table, and so every measure based on it. Many-to-many links and bidirectional filters should be used with great care because they cause ambiguity.

Data Inconsistencies

Common problems are duplicate keys in a dimension, missing keys (a sale for a product not in the product table), different data types, inconsistent spellings and wrong dates. A duplicate key in a dimension table multiplies the matching fact rows and inflates totals. These issues are fixed in Power Query before loading, and validated by checking totals against the source.

Definition: Star schema. A data model with a central fact table of measurable events, linked by keys to surrounding dimension tables that describe the context, such as product, customer and date.

Table 4.4: Fact table and dimension table

Aspect Fact table Dimension table
Contents Events and numbers Descriptive attributes
Example Sales: quantity, amount Product: name, category
Rows Very many Relatively few
Key Foreign keys Unique primary key
Side of relationship Many One

Example 4.4: Totals through a relationship

Problem: The Sales fact table has rows (order, product, amount): (1, P1, 200), (2, P2, 150), (3, P1, 300), (4, P3, 80), (5, P2, 300). The Product dimension gives the category: P1 Stationery, P2 Electronics, P3 Stationery. Find the sales by category, and the total if the P1 row is accidentally duplicated in the Product table.

Solution:

  1. Join Sales to Product on the product key.
  2. Stationery = 200 + 300 + 80 = 580 and Electronics = 150 + 300 = 450; the total is 1,030.
  3. If the Product table has two rows for P1, each of the two P1 sales matches twice, adding 200 + 300 = 500 extra.
  4. The total becomes 1,030 + 500 = 1,530, which is wrong. A unique key prevents this.

Result: Correct totals are Stationery 580 and Electronics 450; a duplicate key inflates the total to 1,530.

import pandas as pd
sales = pd.DataFrame({
    "Order": [1, 2, 3, 4, 5],
    "Product": ["P1", "P2", "P1", "P3", "P2"],
    "Amount": [200, 150, 300, 80, 300]})
prod = pd.DataFrame({"Product": ["P1", "P2", "P3"],
                     "Category": ["Stationery", "Electronics",
                                  "Stationery"]})
m = sales.merge(prod, on="Product")
print(m.groupby("Category")["Amount"].sum().to_string())
print("Total:", m["Amount"].sum())
bad = pd.concat([prod, prod.iloc[[0]]])
dup = sales.merge(bad, on="Product")["Amount"].sum()
print("With duplicate key:", dup)

Output

Category
Electronics    450
Stationery     580
Total: 1030
With duplicate key: 1530

Common mistakes

  • Loading one huge flat table instead of a star schema.
  • Having duplicate values in a dimension's key column.
  • Using many-to-many relationships without need.
  • Not checking model totals against the source data.

Key takeaways

  • Star schema: one fact table surrounded by dimension tables.
  • Relationships are one-to-many; filters flow from the one side to the many side.
  • A duplicate key in a dimension inflates totals.
  • Check totals after every load.

Practice questions

  1. What does a fact table contain?
  2. In which direction does a filter normally flow?
  3. What happens if a dimension has a duplicate key?

Answers to the practice questions

  1. Events and numerical measures such as quantity and amount, with foreign keys.
  2. From the dimension (one side) to the fact table (many side).
  3. Fact rows are matched twice, so the totals become inflated.

Sources

  • Official BCA syllabus Data Visualization, course code 26BCA404DSE11, Unit IV