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.

Intermediate 18 min read

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

DAX
= RELATED ( Products[Category] )

= Sales[Qty] * RELATED ( Products[Price] )
Two calculated columns in Sales, named Category and List Value.
ABCDE
1OrderIDProductIDQtyCategoryList Value
21001P12Computers1900
31002P210Accessories120
41003P33Displays567
51004P45Accessories175
61005P54Computers1680
71006P11Computers950

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:

DAX
List Value := SUMX ( Sales, Sales[Qty] * RELATED ( Products[Price] ) )
RELATED inside an iterator: no stored column needed.

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.

Watch out. 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:

DAX
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" )
)
Three calculated columns in Customers (type each formula after = in the formula bar).
ABCDEF
1CustomerIDCustomerRegionOrdersCustomer RevenueTier
2C1Anna WeberNorth32495Gold
3C2Brook DentalSouth31280Silver
4C3Carter & CoEast2807Bronze
5C4Delta SchoolsWest22058Gold

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:

DAX
Revenue := SUM ( Sales[Amount] )
Customer Count := COUNTROWS ( Customers )
Revenue per Customer := DIVIDE ( [Revenue], [Customer Count] )
ABCD
1TierRevenueCustomersRevenue per Customer
2Bronze8071807.00
3Gold455322,276.50
4Silver128011,280.00
5Grand Total664041,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.

Note. Calculated columns are computed at refresh time and do not react to slicers. If someone filters the PivotTable to March, a customer's Tier stays the one based on all sales. That is often what you want for a stable segmentation. If the tier must change with the selected period, it has to be a measure-driven pattern instead, which is considerably more advanced.

The same idea on Products

DAX
Orders = COUNTROWS ( RELATEDTABLE ( Sales ) )
Units Sold = SUMX ( RELATEDTABLE ( Sales ), Sales[Qty] )
Last Sale = MAXX ( RELATEDTABLE ( Sales ), Sales[Date] )
Calculated columns in Products.
ABCDEF
1ProductIDProductPriceOrdersUnits SoldLast Sale
2P1Laptop950232026-02-17
3P2Mouse122302026-03-03
4P3Monitor189252026-03-10
5P4Keyboard352112026-03-25
6P5Tablet420252026-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:

DAX
Region Target = LOOKUPVALUE ( Targets[Target], Targets[Region], Customers[Region] )
LOOKUPVALUE ( result_column, search_column, search_value, ... )

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

FunctionDirectionReturnsNeeds
RELATEDMany → oneOne valueRow context on the many side
RELATEDTABLEOne → manyA table of related rowsRow context on the one side
LOOKUPVALUEAny, by matching valuesOne valueNo relationship needed

Check yourself

1. In which table can you write RELATED ( Products[Price] )?

2. What does RELATEDTABLE ( Sales ) return in a Customers calculated column?

3. Why can Tier go into a slicer but Revenue per Customer cannot?

4. A Tier calculated column is based on all-time revenue. What happens when a slicer selects March?

5. When is LOOKUPVALUE the right tool?