Sub topic 1
The Building Blocks of a Power BI Model
A Power BI semantic model contains tables, columns, and relationships. A star schema organizes these objects around a central fact table and several dimension tables. This shape makes filtering and measures easier to understand.
Prerequisites
Assume you know how to load data into Power BI Desktop, use Model view, and write simple DAX. You should also know the difference between a primary key and a foreign key.
Deciding the Grain Before Anything Else
The grain is what one row represents. Define it before creating tables or measures. For example, one row might represent one product on one sales order. A different table might contain one row per order.
A fact table should have one consistent grain. If order totals and order-line products share a table without a clear rule, totals can be duplicated. Write the grain as a sentence:
> One row in this table represents one order line.
Fact Tables: Events and Numeric Measurements
A fact table stores events or transactions. It usually contains foreign keys, such as ProductKey and DateKey, plus numeric values that can be added or analyzed.
For an order-line fact table, useful columns include quantity, sales amount, discount, and cost. Keep descriptive text out of the fact table when that text belongs to a product, customer, or date.
CREATE TABLE FactSales (
OrderNumber VARCHAR(20) NOT NULL,
OrderLineNumber INT NOT NULL,
DateKey INT NOT NULL,
ProductKey INT NOT NULL,
Quantity INT NOT NULL,
SalesAmount DECIMAL(18, 2) NOT NULL,
PRIMARY KEY (OrderNumber, OrderLineNumber)
);Dimension Tables: The Context You Slice By
A dimension table describes the events in a fact table. It contains attributes used in slicers, filters, and grouping. Product, customer, store, and date are common dimensions.
A product dimension might contain one row per product, with its name, category, and subcategory. Its columns provide the context for measures such as total sales by category.
Keys That Connect Facts to Dimensions
A key identifies a row. A fact table stores a foreign key that points to a dimension row. A dimension often uses a surrogate key, an internal integer that remains stable even when source-system IDs change.
The usual relationship is one dimension row to many fact rows. Configure it with single-direction filtering from the dimension to the fact.
Exercise
What grain should FactSales use if each row stores one product on one order?
Show answer
Its grain is one order line per product, identified by the order and line keys.