DAX Tutorial: Related Function in Power BI.

The RELATED function requires that a regular relationship exists between the current table and the table with related information. The argument specifies a column reference, and the function follows a chain of one or more many-to-one relationships to fetch the value from the specified column in the related table. If a relationship does not exist, RELATED raises an error. The RELATED function cannot be used to fetch a column across a limited relationship. In this blog post, we will explore the “RELATED” function in DAX and provide a detailed explanation of its usage.

Introduction to the RELATED Function

The RELATED function in DAX is used to retrieve data from a related table based on a common column between two tables. It is particularly useful when working with multiple tables that have a relationship defined in the data model. The RELATED function allows you to access data from the related table without the need for complex joins or lookups.

Syntax and Parameters

The syntax of the RELATED function is as follows:

RELATED(table[column])

The function takes a single parameter, which is the column you want to retrieve data from in the related table. The “table” parameter is optional if there is only one related table in the data model. If there are multiple related tables, you need to specify the table name within the function.

Example Usage

Let’s consider a simple example to understand how the RELATED function works. Suppose we have two tables in our data model: “Sales” and “Products”. The “Sales” table contains information about sales transactions, while the “Products” table contains details about the products sold.

The “Sales” table has a relationship with the “Products” table based on the common column “ProductID”. We want to calculate the total sales amount for each product. To achieve this, we can use the RELATED function to retrieve the product name from the “Products” table.

Here’s an example DAX formula that uses the RELATED function:

Total Sales Amount = SUM(Sales[Quantity] * RELATED(Products[Price]))

In this formula, we multiply the quantity of each sale by the price of the related product to calculate the total sales amount. The RELATED function retrieves the price from the “Products” table based on the common “ProductID” column.

Limitations and Considerations

While the RELATED function is a powerful tool in DAX, there are a few limitations and considerations to keep in mind:

  1. The RELATED function can only be used in calculated columns or measures, not in calculated tables.
  2. The function can only retrieve data from a single column in the related table.
  3. If there are multiple relationships between tables, you need to specify the table name within the function to avoid ambiguity.
  4. The RELATED function can only be used when there is an active relationship between the tables. If the relationship is inactive, you need to use the USERELATIONSHIP function to specify the relationship explicitly.

Conclusion

The RELATED function in Power BI DAX is a powerful tool for retrieving data from related tables in the data model. It simplifies the process of accessing data without the need for complex joins or lookups. By understanding the syntax and usage of the RELATED function, you can enhance your data analysis and visualization capabilities in Power BI.

Remember to leverage the power of the RELATED function in your DAX calculations, but also be aware of its limitations and considerations to ensure accurate and efficient data analysis.

Leave a Comment