Power Pivot & DAX course · Lesson 10 of 16
RELATED and RELATEDTABLE: working across relationships
Use DAX RELATED to fetch values from lookup tables and RELATEDTABLE to count and sum related rows, build customer tiers, and when to use LOOKUPVALUE.
Relationships let filters flow through the model automatically. Sometimes, though, a formula needs to reach across a relationship explicitly: a Sales row needs its product's price, or a Customers row needs a list of that customer's orders. RELATED and RELATEDTABLE do exactly that. They are the DAX replacements for the lookup formulas you would write on a worksheet with XLOOKUP or SUMIFS, and they work only where a relationship exists.
RELATED: from the many side to the one side
RELATED ( Table[Column] ) returns a single value from the table on the one side of a relationship, for the current row of the table on the many side. It needs a row context, so it appears in calculated columns and inside iterators.
= RELATED ( Products[Category] )
= Sales[Qty] * RELATED ( Products[Price] )| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | OrderID | ProductID | Qty | Category | List Value |
| 2 | 1001 | P1 | 2 | Computers | 1900 |
| 3 | 1002 | P2 | 10 | Accessories | 120 |
| 4 | 1003 | P3 | 3 | Displays | 567 |
| 5 | 1004 | P4 | 5 | Accessories | 175 |
| 6 | 1005 | P5 | 4 | Computers | 1680 |
| 7 | 1006 | P1 | 1 | Computers | 950 |
First six Sales rows with the two calculated columns.
For order 1005 the row context is on a Sales row with ProductID P5. RELATED follows the Sales → Products relationship to the Tablet row and returns Computers and the price 420; 4 × 420 = 1,680. This is like an XLOOKUP that never misses, as long as the relationship and keys are correct.
Do you even need the column?
In a star schema you usually do not need to copy Category into Sales. A PivotTable can already put Products[Category] on rows and the filter will flow to Sales. Copying attributes into the fact table wastes memory and duplicates what the relationship already provides. The second column, List Value, is a better use, but as you saw in Iterators in DAX: SUMX, AVERAGEX, MAXX and RANKX it is usually even better as a measure:
List Value := SUMX ( Sales, Sales[Qty] * RELATED ( Products[Price] ) )RELATED can travel several hops in the same direction. In a snowflake where Products relates to a Categories table, RELATED ( Categories[Department] ) works from Sales, as long as every hop goes from many to one.
RELATED works in one direction only. Writing RELATED ( Sales[Qty] ) in a Products column fails with an error saying the column either does not exist or has no relationship to any table available in the current context. From the one side you need RELATEDTABLE.RELATEDTABLE: from the one side to the many side
RELATEDTABLE ( Table ) returns all the rows of the many-side table that are related to the current row. It returns a table, so you wrap it in something that produces a single value: COUNTROWS, SUMX, MAXX. Add these calculated columns to Customers:
Orders = COUNTROWS ( RELATEDTABLE ( Sales ) )
Customer Revenue = SUMX ( RELATEDTABLE ( Sales ), Sales[Amount] )
Tier =
IF (
Customers[Customer Revenue] >= 2000, "Gold",
IF ( Customers[Customer Revenue] >= 1000, "Silver", "Bronze" )
)| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | CustomerID | Customer | Region | Orders | Customer Revenue | Tier |
| 2 | C1 | Anna Weber | North | 3 | 2495 | Gold |
| 3 | C2 | Brook Dental | South | 3 | 1280 | Silver |
| 4 | C3 | Carter & Co | East | 2 | 807 | Bronze |
| 5 | C4 | Delta Schools | West | 2 | 2058 | Gold |
Customers after adding the three columns.
Anna Weber has three orders worth 2,495, so she is Gold. RELATEDTABLE is in fact a shortcut for CALCULATETABLE with context transition: the current Customers row becomes a filter on Sales, and the related rows come back. That is why Customer Revenue here gives the same values as the CALCULATE ( SUM ( Sales[Amount] ) ) column of Filter context and row context in DAX.
Using the new column to slice
Because Tier is a column, it can go on rows or into a slicer, something a measure cannot do. A PivotTable with Customers[Tier] on rows and two measures:
Revenue := SUM ( Sales[Amount] )
Customer Count := COUNTROWS ( Customers )
Revenue per Customer := DIVIDE ( [Revenue], [Customer Count] )| A | B | C | D | |
|---|---|---|---|---|
| 1 | Tier | Revenue | Customers | Revenue per Customer |
| 2 | Bronze | 807 | 1 | 807.00 |
| 3 | Gold | 4553 | 2 | 2,276.50 |
| 4 | Silver | 1280 | 1 | 1,280.00 |
| 5 | Grand Total | 6640 | 4 | 1,660.00 |
Customers[Tier] on rows (alphabetical order). Revenue per Customer with 2 decimals.
Two Gold customers bring 4,553 of the 6,640 total. Note that Customer Count works here because the filter is on the Customers table itself; we are not crossing a relationship in the wrong direction.
The same idea on Products
Orders = COUNTROWS ( RELATEDTABLE ( Sales ) )
Units Sold = SUMX ( RELATEDTABLE ( Sales ), Sales[Qty] )
Last Sale = MAXX ( RELATEDTABLE ( Sales ), Sales[Date] )| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | ProductID | Product | Price | Orders | Units Sold | Last Sale |
| 2 | P1 | Laptop | 950 | 2 | 3 | 2026-02-17 |
| 3 | P2 | Mouse | 12 | 2 | 30 | 2026-03-03 |
| 4 | P3 | Monitor | 189 | 2 | 5 | 2026-03-10 |
| 5 | P4 | Keyboard | 35 | 2 | 11 | 2026-03-25 |
| 6 | P5 | Tablet | 420 | 2 | 5 | 2026-03-18 |
Products with three RELATEDTABLE columns. Last Sale formatted as a date.
A product with no sales would show blank in all three columns. That makes such columns useful for data quality checks, such as finding products that have never been sold, or customers with no orders since a certain date.
LOOKUPVALUE: when there is no relationship
Sometimes a small table cannot be related, for example a Targets table keyed by Region, while Region is not a unique key anywhere. LOOKUPVALUE searches by value instead of by relationship:
Region Target = LOOKUPVALUE ( Targets[Target], Targets[Region], Customers[Region] )It is slower than RELATED and returns an error if it finds several different values, so use it only when a relationship is not possible. In most cases the better fix is a proper dimension table (a Regions table) related to both Customers and Targets.
Quick reference
| Function | Direction | Returns | Needs |
|---|---|---|---|
| RELATED | Many → one | One value | Row context on the many side |
| RELATEDTABLE | One → many | A table of related rows | Row context on the one side |
| LOOKUPVALUE | Any, by matching values | One value | No relationship needed |
Check yourself
1. In which table can you write RELATED ( Products[Price] )?
RELATED goes from the many side to the one side.
2. What does RELATEDTABLE ( Sales ) return in a Customers calculated column?
It returns the related rows on the many side.
3. Why can Tier go into a slicer but Revenue per Customer cannot?
Slicers, rows and columns need columns.
4. A Tier calculated column is based on all-time revenue. What happens when a slicer selects March?
Calculated columns do not respond to filter context.
5. When is LOOKUPVALUE the right tool?
It searches by value; RELATED is faster when a relationship exists.