RELATED Vs RELATEDTABLE DAX Function in Power BI
RELATED and RELATEDTABLE are two powerful functions in DAX that help you navigate relationships between tables and retrieve data from related tables based on the current row context.
You should have a good understanding of your data model and the relationships between tables to use these functions effectively.
RELATED Function: The RELATED function is used to fetch a single column value from a related table.
It is commonly used in scenarios where you have established one to many relationship between tables in your data model.
You can write the related function only in many side of the table.
Let’s say you want add a product name column from DimProduct table to Sales table.
Recommended by LinkedIn
ProductName = RELATED(DimProduct[Product])
But if we try the same function on any Dimension table, It won’t work.
We can use Related function to create measures by understanding row context.
TotalSales =
SUMX(Sales,
RELATED(DimProduct[Price])*Sales[Units])
RELATEDTABLE Function: On the other hand, the RELATEDTABLE function is used to fetch a table of values from a related table. This function returns a table, not a single value.
It can work with both one-to-many, many-to-many and many-to -one relationships.
let’s say we want to count how many rows are there for each product from sales table.
Col = COUNTROWS(RELATEDTABLE(Sales))
Difference
The key difference is that RELATED returns a single column value, while RELATEDTABLE returns a table. RELATED is used when you want to get a specific value from a related table, and RELATEDTABLE is used when you want to get a table of values from a related table. In summary, RELATED is for getting a specific value, and RELATEDTABLE is for getting a table of values from a related table. Both are essential in building more complex DAX expressions, especially in scenarios involving relationships between tables.