๐——๐—ฎ๐˜† ๐Ÿณ: ๐— ๐—ฎ๐—ป๐—ฎ๐—ด๐—ถ๐—ป๐—ด ๐—ฅ๐—ฒ๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€๐—ต๐—ถ๐—ฝ๐˜€ ๐—ถ๐—ป ๐——๐—”๐—ซ

Kingsley Andy
2 min readSep 7, 2024

--

In Power BI, relationships between tables are crucial for building complex data models. DAX allows you to harness these relationships and perform calculations across multiple tables. Today, weโ€™ll dive into how to manage relationships using DAX functions such as RELATED, RELATEDTABLE, and LOOKUPVALUE.
๐—ž๐—ฒ๐˜† ๐——๐—”๐—ซ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€:
1. RELATED()
What it does: Retrieves a value from a related table.
When to use: When you need to pull data from another table with a one-to-many relationship.
Example: Suppose you have a Sales table and a Products table, and you want to bring the Product Category from the Products table into the Sales table.
๐šฬฒ๐™ดฬฒ๐™ปฬฒ๐™ฐฬฒ๐šƒฬฒ๐™ดฬฒ๐™ณฬฒ(ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ๐šœฬฒ[ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ ฬฒ๐™ฒฬฒ๐šŠฬฒ๐šฬฒ๐šŽฬฒ๐šฬฒ๐š˜ฬฒ๐š›ฬฒ๐šขฬฒ]ฬฒ)ฬฒ
2. RELATEDTABLE()
What it does: Returns all rows from a related table where there is a matching row in the current table.
When to use: When you want to see all related rows for a particular entry.
Example: Letโ€™s say you have a Customers table and want to get all sales transactions for each customer from a related Sales table.
๐šฬฒ๐™ดฬฒ๐™ปฬฒ๐™ฐฬฒ๐šƒฬฒ๐™ดฬฒ๐™ณฬฒ๐šƒฬฒ๐™ฐฬฒ๐™ฑฬฒ๐™ปฬฒ๐™ดฬฒ(ฬฒ๐š‚ฬฒ๐šŠฬฒ๐š•ฬฒ๐šŽฬฒ๐šœฬฒ)ฬฒ
3. LOOKUPVALUE()
What it does: Returns the value from a column in another table based on a matching condition.
When to use: When you need to retrieve a specific value from another table without a direct relationship.
Example: Looking up the Sales Amount from a Sales table where the Customer ID matches:
๐™ปฬฒ๐™พฬฒ๐™พฬฒ๐™บฬฒ๐š„ฬฒ๐™ฟฬฒ๐š…ฬฒ๐™ฐฬฒ๐™ปฬฒ๐š„ฬฒ๐™ดฬฒ(ฬฒ๐š‚ฬฒ๐šŠฬฒ๐š•ฬฒ๐šŽฬฒ๐šœฬฒ[ฬฒ๐š‚ฬฒ๐šŠฬฒ๐š•ฬฒ๐šŽฬฒ๐šœฬฒ ฬฒ๐™ฐฬฒ๐š–ฬฒ๐š˜ฬฒ๐šžฬฒ๐š—ฬฒ๐šฬฒ]ฬฒ,ฬฒ ฬฒ๐š‚ฬฒ๐šŠฬฒ๐š•ฬฒ๐šŽฬฒ๐šœฬฒ[ฬฒ๐™ฒฬฒ๐šžฬฒ๐šœฬฒ๐šฬฒ๐š˜ฬฒ๐š–ฬฒ๐šŽฬฒ๐š›ฬฒ ฬฒ๐™ธฬฒ๐™ณฬฒ]ฬฒ,ฬฒ ฬฒ๐™ฒฬฒ๐šžฬฒ๐šœฬฒ๐šฬฒ๐š˜ฬฒ๐š–ฬฒ๐šŽฬฒ๐š›ฬฒ๐šœฬฒ[ฬฒ๐™ฒฬฒ๐šžฬฒ๐šœฬฒ๐šฬฒ๐š˜ฬฒ๐š–ฬฒ๐šŽฬฒ๐š›ฬฒ ฬฒ๐™ธฬฒ๐™ณฬฒ]ฬฒ)ฬฒ
Practical Example:
Imagine youโ€™re working with three tables: Orders, Customers, and Products. The Orders table contains customer and product IDs but not the actual customer names or product categories. Hereโ€™s how you can bring that information into the Orders table using DAX:
1. Adding Customer Names to Orders:
๐šฬฒ๐™ดฬฒ๐™ปฬฒ๐™ฐฬฒ๐šƒฬฒ๐™ดฬฒ๐™ณฬฒ(ฬฒ๐™ฒฬฒ๐šžฬฒ๐šœฬฒ๐šฬฒ๐š˜ฬฒ๐š–ฬฒ๐šŽฬฒ๐š›ฬฒ๐šœฬฒ[ฬฒ๐™ฒฬฒ๐šžฬฒ๐šœฬฒ๐šฬฒ๐š˜ฬฒ๐š–ฬฒ๐šŽฬฒ๐š›ฬฒ ฬฒ๐™ฝฬฒ๐šŠฬฒ๐š–ฬฒ๐šŽฬฒ]ฬฒ)ฬฒ
2. Adding Product Categories to Orders:
๐šฬฒ๐™ดฬฒ๐™ปฬฒ๐™ฐฬฒ๐šƒฬฒ๐™ดฬฒ๐™ณฬฒ(ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ๐šœฬฒ[ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ ฬฒ๐™ฒฬฒ๐šŠฬฒ๐šฬฒ๐šŽฬฒ๐šฬฒ๐š˜ฬฒ๐š›ฬฒ๐šขฬฒ]ฬฒ)ฬฒ
3. Looking Up a Discount Rate for a Product in Orders:
๐™ปฬฒ๐™พฬฒ๐™พฬฒ๐™บฬฒ๐š„ฬฒ๐™ฟฬฒ๐š…ฬฒ๐™ฐฬฒ๐™ปฬฒ๐š„ฬฒ๐™ดฬฒ(ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ๐šœฬฒ[ฬฒ๐™ณฬฒ๐š’ฬฒ๐šœฬฒ๐šŒฬฒ๐š˜ฬฒ๐šžฬฒ๐š—ฬฒ๐šฬฒ ฬฒ๐šฬฒ๐šŠฬฒ๐šฬฒ๐šŽฬฒ]ฬฒ,ฬฒ ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ๐šœฬฒ[ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ ฬฒ๐™ธฬฒ๐™ณฬฒ]ฬฒ,ฬฒ ฬฒ๐™พฬฒ๐š›ฬฒ๐šฬฒ๐šŽฬฒ๐š›ฬฒ๐šœฬฒ[ฬฒ๐™ฟฬฒ๐š›ฬฒ๐š˜ฬฒ๐šฬฒ๐šžฬฒ๐šŒฬฒ๐šฬฒ ฬฒ๐™ธฬฒ๐™ณฬฒ]ฬฒ)ฬฒ
What are your experiences working with relationships in Power BI? Do you have any tips or challenges when using RELATED or LOOKUPVALUE? Share your thoughts in the comments!

hashtag#PowerBI hashtag#DAX hashtag#DataRelationships hashtag#DataAnalysis hashtag#PowerBItips hashtag#10DaysOfDAX

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kingsley Andy
Kingsley Andy

Written by Kingsley Andy

Data Analyst || Power Platform Developer || CareersHelp

No responses yet

Write a response