How to Use the RELATED Function in DAX: Step by Step
The RELATED function in DAX fetches a value from another table by following a relationship that already exists in your model. It is especially useful in a star schema, where the fact table (your sales) is separated from the dimensions (products, customers or dates). With a simple sales-and-products example, you will learn how to use RELATED to place the right price and category on every sales row.
Prerequisites
- Power BI Desktop installed (the function also exists in Excel Power Pivot and in Analysis Services).
- Two tables in the model: a fact table,
Sales, and a dimension table,Products. - A relationship between the two tables, joined by a common column such as
ProductID. - Knowing how to create a calculated column (just right-click the table).
Step 1: Understand the data model
Picture two tables. The Sales table stores each order line and has the columns ProductID and Quantity. The Products table describes each item and has ProductID, ProductName, Category and UnitPrice. Between them there is a many-to-one relationship: many sales point to the same product.
The goal is a common one: you want the total of each sales line (quantity × price), but the price lives in the Products table, not in Sales. This is exactly what the RELATED function is for.
Step 2: Confirm that a relationship exists
RELATED only works if there is a relationship between the tables. Open the Model view in Power BI Desktop and confirm that a line connects Sales[ProductID] to Products[ProductID]. The "one" side is the Products table (each product appears once) and the "many" side is the Sales table.
RELATED always follows the relationship from the "many" side to the "one" side. In other words, you call it from the fact table to fetch values from the dimension.
Step 3: Create a calculated column with RELATED
Select the Sales table, create a new column and type the formula below. It brings the matching product's unit price into the sales table:
UnitPrice = RELATED( Products[UnitPrice] )
Notice that you only state the column you want — Products[UnitPrice]. You do not need to say which relationship to use: DAX finds the path on its own, because the relationship already exists in the model.
Step 4: Calculate each line total
With the price available on every row, you can now compute the value of each sale. Create another calculated column in the Sales table:
LineTotal = Sales[Quantity] * RELATED( Products[UnitPrice] )
This works because a calculated column has row context: DAX knows which row it is on and therefore which product to look up. In the same way, you can bring in the category to group your sales later:
Category = RELATED( Products[Category] )
Step 5: Use RELATED inside a measure with SUMX
You do not always want physical columns. You can use RELATED inside an iterator such as SUMX, which scans the table row by row and creates, on each one, the row context that RELATED needs:
Total Sales =
SUMX(
Sales,
Sales[Quantity] * RELATED( Products[UnitPrice] )
)
This measure returns total sales without taking up space with calculated columns — a good practice in large models.
Step 6: A common error and the reverse function
A frequent error is using RELATED in a plain measure, like = RELATED( Products[UnitPrice] ). It does not work: a measure has no row context, so DAX returns an error. Use RELATED only in calculated columns or inside iterators (SUMX, AVERAGEX, FILTER and the like).
If you need the opposite direction — from the "one" side to the "many" side — use RELATEDTABLE. For example, to count how many sales each product had, create this column in the Products table:
NumSales = COUNTROWS( RELATEDTABLE( Sales ) )
Verify the result
Create a table visual with Products[ProductName] and the Total Sales measure. The values should match the manual sum of quantity × price for each product. Also check the LineTotal column: pick any row and see whether the result really is the quantity multiplied by that product's UnitPrice. If you get (Blank) or an error, check that the relationship exists and that the ProductID values match across both tables.
Conclusion
You have learned to use the RELATED function to pull values from a dimension into the fact table by following the model's relationships, and to use RELATEDTABLE for the reverse path. The next step is to combine RELATED with CALCULATE to build richer metrics, or to dig into how row context and filter context relate to each other. Which column will you stop copying by hand first, thanks to RELATED?