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.

Advanced 20 min read

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.
Note. The Data Model and relationships work in Excel 2016 and later on Windows. The Power Pivot window (for DAX measures and Diagram View) is included in all Windows editions of Excel 2019, 2021, 2024 and Microsoft 365; in Excel 2016 it depended on the edition. It is not available in Excel for Mac or the web, although those versions can display PivotTables built on a model.

The example tables

ABCDE
1SaleIDDateProductIDRegionQty
2S12026-03-02P1North3
3S22026-03-03P2South10
4S32026-03-05P1East2
5S42026-03-06P3North1
6S52026-03-09P2North5

Table Sales (the fact table): one row per sale.

ABCD
1ProductIDProductCategoryPrice
2P1LaptopComputers950
3P2MouseAccessories12
4P3MonitorDisplays189

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

  1. Convert both ranges into Excel tables (Ctrl+T) and name them Sales and Products in Table Design › Table Name.
  2. Click inside Sales and choose Insert › PivotTable. In the dialog tick Add this data to the Data Model and click OK.
  3. In the PivotTable Fields pane, click All at the top. Both tables are listed (Excel adds Products to the model when you use it).
  4. 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

  1. Choose Data › Data Tools › Relationships and click New.
  2. Table: Sales, Column (Foreign): ProductID.
  3. Related Table: Products, Related Column (Primary): ProductID.
  4. Click OK. Or, in the Power Pivot window, switch to Home › Diagram View and drag ProductID from Sales onto ProductID in Products. A line with * at the Sales end and 1 at the Products end appears: a one-to-many relationship.
Watch out. The key on the 'one' side must be unique. If Products contained P2 twice, Excel refuses the relationship. Also make sure both key columns have the same data type: a ProductID stored as number in one table and as text in the other will not match.

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.

Tip. If a yellow banner says 'Relationships between tables may be needed', Excel has not found a relationship between the fields you used. Create it rather than clicking Auto-Detect blindly, and check that it connects the right columns.

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).

  1. Choose Power Pivot › Calculations › Measures › New Measure (or right-click the Sales table in the PivotTable Fields pane and choose Add Measure).
  2. Table name: Sales. Measure name: Revenue.
  3. Formula: =SUMX(Sales, Sales[Qty] * RELATED(Products[Price])).
  4. Click Check formula, set Category: Currency or Number with 0 decimals, and click OK.
  5. The measure appears in the field list with an fx icon. Drag it to Values.
DAX
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 ) ) )
Five measures. In the Measure dialog type only the part after :=.
CategoryUnitsRevenueAvg PriceRevenue %
Accessories15180123.5%
Computers54,75095092.8%
Displays11891893.7%
Grand Total215,119243.76100.0%

Reading the measures

  • SUMX goes row by row through Sales, multiplies Qty by the related Price, and adds the results. The X functions (SUMX, AVERAGEX) are iterators.
  • RELATED fetches a value from the 'one' side of a relationship, like a lookup that follows the relationship.
  • DIVIDE divides and returns blank instead of an error when the divisor is zero.
  • CALCULATE changes the filter context: Revenue North always 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 columnMeasure
CalculatedOnce per row, stored in the modelOn the fly, per PivotTable cell
Use forValues to slice or filter by (price band, year)Numbers to aggregate (totals, ratios, %)
MemoryUses memory for every rowNo 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?

2. What must be true of Products[ProductID] for a one-to-many relationship?

3. Which DAX function fetches a value from the related lookup table inside a row-by-row calculation?

4. Margin % should be created as…

5. Where can you write DAX measures?