Power BI is a powerful tool that allows you to build dynamic reports by connecting tables through relationships. In this tutorial by Justin Vogel from Pragmatic Works, we dive into two essential DAX functions: RELATED and RELATEDTABLE, which can greatly enhance your ability to work across multiple tables in your Power BI data model. These functions make it easier to pull data from related tables and create smarter, more dynamic reports. Let’s break down these functions and how they can be applied effectively in Power BI.
Before using the RELATED and RELATEDTABLE functions, it’s crucial to understand how relationships work in Power BI. Relationships typically follow a one-to-many or many-to-one model, where one table (the “one” side) is linked to another (the “many” side) via a shared column. For example, in a customer-orders relationship, one customer can have many orders. Understanding the direction of these relationships is key to choosing the right DAX function.
The RELATED function allows you to pull a value from a related table into your current table, based on a pre-established relationship. This function works from the "many" side of the relationship to the "one" side. Think of it like Excel’s VLOOKUP but much more powerful and dynamic, as it works with the entire relationship model and adapts to any filters applied.
RELATED(Customers[CustomerName])Unlike the RELATED function, RELATEDTABLE works in the opposite direction. It is used to bring in a table of related rows from the "one" side to the "many" side. This is especially useful for aggregations, where you want to count or sum the rows related to a specific item (e.g., counting the number of orders for each customer).
COUNTROWS(RELATEDTABLE(Orders))One of the best ways to use RELATEDTABLE is in combination with aggregation functions like SUMX or AVERAGEX. These iterator functions evaluate an expression row by row over a table and then summarize the results.
Let’s see how to use the RELATEDTABLE and SUMX functions to calculate total sales per customer. In this case, we will multiply the order amount by the quantity ordered, and then sum the results for each customer.
SUMX(RELATEDTABLE(Orders), Orders[Amount] * Orders[Quantity])In this tutorial, we covered the RELATED and RELATEDTABLE functions in DAX, which are essential for working with data across multiple tables in Power BI. RELATED helps you pull values from a related table to the current row, while RELATEDTABLE allows you to bring in related rows for aggregation purposes. By understanding these functions and applying them in your reports, you can create more powerful and dynamic Power BI dashboards. For more advanced Power BI tips and tricks, stay tuned for more tutorials from Pragmatic Works.
Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on Power BI and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks.