Excel course · Lesson 25 of 34
Power Pivot and the Data Model: relationships and DAX measures
Combine several tables without VLOOKUP using the Data Model, create relationships, and write your first DAX measures with SUM, DIVIDE, CALCULATE and SUMX.
A normal PivotTable summarises one table. Real data usually lives in several: a sales table with product codes, a product table with categories and prices, a customer table with regions. The traditional fix is a forest of VLOOKUP columns that copy information into one giant table. The Data Model offers a cleaner route: load each table once, connect them with relationships, and build PivotTables across all of them. Power Pivot is the window for managing the model and writing DAX measures, formulas designed for summaries.
Why use the Data Model
- No lookup columns: relationships replace VLOOKUP and XLOOKUP for reporting.
- Size: the model compresses data in memory and handles millions of rows, far beyond a worksheet's 1,048,576.
- Measures: reusable calculations (margin %, year-on-year growth) that work in every PivotTable.
- Distinct count: a PivotTable based on the model can count unique customers, which a normal PivotTable cannot.
- Same engine as Power BI: what you learn here transfers directly.
The example tables
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | SaleID | Date | ProductID | Region | Qty |
| 2 | S1 | 2026-03-02 | P1 | North | 3 |
| 3 | S2 | 2026-03-03 | P2 | South | 10 |
| 4 | S3 | 2026-03-05 | P1 | East | 2 |
| 5 | S4 | 2026-03-06 | P3 | North | 1 |
| 6 | S5 | 2026-03-09 | P2 | North | 5 |
Table Sales (the fact table): one row per sale.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | ProductID | Product | Category | Price |
| 2 | P1 | Laptop | Computers | 950 |
| 3 | P2 | Mouse | Accessories | 12 |
| 4 | P3 | Monitor | Displays | 189 |
Table Products (a lookup or dimension table): one row per product, ProductID is unique.
This is the classic star schema: a central fact table of transactions surrounded by lookup tables that describe them. Each lookup table has a unique key column; the fact table refers to that key many times.
Loading tables into the model
- Convert both ranges into Excel tables (
Ctrl+T) and name themSalesandProductsin Table Design › Table Name. - Click inside
Salesand choose Insert › PivotTable. In the dialog tick Add this data to the Data Model and click OK. - In the PivotTable Fields pane, click All at the top. Both tables are listed (Excel adds Products to the model when you use it).
- Alternatively, open Data › Data Tools › Manage Data Model (or Power Pivot › Manage), and use Power Pivot › Add to Data Model while inside each table. Power Query can also load straight to the model with Close & Load To › Only Create Connection and Add this data to the Data Model.
Creating a relationship
- Choose Data › Data Tools › Relationships and click New.
- Table: Sales, Column (Foreign): ProductID.
- Related Table: Products, Related Column (Primary): ProductID.
- Click OK. Or, in the Power Pivot window, switch to Home › Diagram View and drag
ProductIDfrom Sales ontoProductIDin Products. A line with*at the Sales end and1at the Products end appears: a one-to-many relationship.
A PivotTable across two tables
Now build a PivotTable from the model: drag Products › Category to Rows and Sales › Qty to Values. Excel follows the relationship to find each sale's category: Accessories 15, Computers 5, Displays 1. No lookup column exists anywhere.
DAX measures
Quantity is easy, but revenue needs price from Products multiplied by quantity in Sales. That is a job for a measure, a named DAX formula that is calculated for whatever the PivotTable cell represents (a category, a region, a month).
- Choose Power Pivot › Calculations › Measures › New Measure (or right-click the Sales table in the PivotTable Fields pane and choose Add Measure).
- Table name: Sales. Measure name:
Revenue. - Formula:
=SUMX(Sales, Sales[Qty] * RELATED(Products[Price])). - Click Check formula, set Category: Currency or Number with 0 decimals, and click OK.
- The measure appears in the field list with an fx icon. Drag it to Values.
Revenue := SUMX ( Sales, Sales[Qty] * RELATED ( Products[Price] ) )
Units := SUM ( Sales[Qty] )
Avg Price := DIVIDE ( [Revenue], [Units] )
Revenue North := CALCULATE ( [Revenue], Sales[Region] = "North" )
Revenue % := DIVIDE ( [Revenue], CALCULATE ( [Revenue], ALL ( Products ) ) )| Category | Units | Revenue | Avg Price | Revenue % |
|---|---|---|---|---|
| Accessories | 15 | 180 | 12 | 3.5% |
| Computers | 5 | 4,750 | 950 | 92.8% |
| Displays | 1 | 189 | 189 | 3.7% |
| Grand Total | 21 | 5,119 | 243.76 | 100.0% |
Reading the measures
SUMXgoes row by row through Sales, multiplies Qty by the related Price, and adds the results. TheXfunctions (SUMX, AVERAGEX) are iterators.RELATEDfetches a value from the 'one' side of a relationship, like a lookup that follows the relationship.DIVIDEdivides and returns blank instead of an error when the divisor is zero.CALCULATEchanges the filter context:Revenue Northalways shows North's revenue, whatever the PivotTable rows are. North's revenue is 2,850 + 189 + 60 = 3,099.ALL(Products)removes filters on Products, so the denominator is total revenue across all categories, which makes a share of total.
Filter context is the key DAX idea: in the Computers row of the PivotTable, every measure is calculated only on sales whose product category is Computers. You write a measure once; the PivotTable decides which rows it sees.
Measures versus calculated columns
| Calculated column | Measure | |
|---|---|---|
| Calculated | Once per row, stored in the model | On the fly, per PivotTable cell |
| Use for | Values to slice or filter by (price band, year) | Numbers to aggregate (totals, ratios, %) |
| Memory | Uses memory for every row | No storage |
| Example | =YEAR(Sales[Date]) | =DIVIDE([Revenue],[Units]) |
A rule of thumb: if you would put it in Rows, Columns or a slicer, it is a column; if you would put it in Values, it is a measure. Ratios must be measures; a calculated column of ratios summed in a PivotTable gives nonsense.
A date table
For time analysis (month-to-date, same period last year), add a dedicated date table with one row per day, mark it via Power Pivot › Design › Mark as Date Table, and relate it to Sales[Date]. Power Pivot can create one for you: Design › Date Table › New. Then functions such as TOTALYTD and SAMEPERIODLASTYEAR work correctly.
Cube functions: model data in cells
To put a model value in an ordinary cell, use the cube functions. Select a model-based PivotTable and choose PivotTable Analyze › OLAP Tools › Convert to Formulas; every cell becomes a formula such as =CUBEVALUE("ThisWorkbookDataModel", "[Measures].[Revenue]", "[Products].[Category].&[Computers]"), which you can then move freely around a report.
Check yourself
1. What does a relationship between Sales[ProductID] and Products[ProductID] replace?
The model follows the relationship, so no lookup column is needed.
2. What must be true of Products[ProductID] for a one-to-many relationship?
The 'one' side needs unique keys.
3. Which DAX function fetches a value from the related lookup table inside a row-by-row calculation?
RELATED follows the relationship from the many side to the one side.
4. Margin % should be created as…
Ratios must be calculated per PivotTable cell, which is what measures do.
5. Where can you write DAX measures?
Power Pivot is a Windows-only feature.