Power BI Advanced AnalyticsLesson 34 of 53
Lesson 34 of 53

Logical Branching: IF, AND, OR, NOT & Nested Logic

Overview & Learning Objectives

When working under Row Context (in a Calculated Column or iterator function), filters do NOT automatically traverse relationships. To fetch data across tables, DAX provides two navigation functions: `RELATED()` (travels from the Many side up to the One side to fetch a single scalar value) and `RELATEDTABLE()` (travels from the One side down to the Many side to fetch a table of matching child rows).

  • Master `RELATED(Dimension[Column])` to fetch parent attributes into Fact calculations.
  • Master `RELATEDTABLE(FactTable)` to pull child rows into Dimension summaries.
  • Understand the relationship direction rules required by both functions.

Industry Standard

Standard: Analytics standards at Deloitte and Amazon require using `RELATED` inside `SUMX` iterators rather than creating permanent merge columns in Power Query, keeping models normalized and slim.

Real-World Example: Spice Delight Cloud Kitchen

Spice Delight calculates dish profitability. Fact_Orders has DishID and Quantity. Dim_Dishes (One side) has UnitCost.

Context / LocationRequired OperationFunction to UseResult Returned
In Fact_Orders (Many side)Pull UnitCost from Dim_Dishes (One side)RELATED(Dim_Dishes[UnitCost])Single scalar price (e.g. ₹180)
In Dim_Dishes (One side)Count total order rows in Fact_Orders (Many side)COUNTROWS(RELATEDTABLE(Fact_Orders))Virtual table of matching orders

Functions Covered in this Chapter

Here is the definition, exact syntax, parameter breakdown, and real-world business example for each function covered in this chapter:

Function 1

RELATED Function

Definition: Follows an existing Many-to-One relationship from the "Many" side table to fetch a single matching attribute from the "One" side lookup table in row context.

Syntax:
Product Category Name = RELATED(Dim_Product[CategoryName])
Parameters Breakdown:
  • Column: A column from the related table on the "One" side of the active relationship.
Real-World Example (Pulling Wholesale Cost into Sales Fact Rows):
Problem / Scenario: How do you calculate gross profit inside a calculated column on Fact_Sales by fetching unit cost from Dim_Product?
Formula: Unit Margin = Fact_Sales[UnitPrice] - RELATED(Dim_Product[WholesaleCost])
Result: ₹ 45 margin / unit
Why it works: RELATED traverses the product relationship upwards to the Dim_Product table and returns the exact unit cost.
Function 2

RELATEDTABLE Function

Definition: Follows a relationship in the reverse direction (from the "One" side table to the "Many" side), returning all matching rows as a sub-table.

Syntax:
Customer Lifetime Orders = COUNTROWS(RELATEDTABLE(Fact_Orders))
Parameters Breakdown:
  • Table: The related table on the "Many" side of an active relationship.
Real-World Example (Counting Orders per Customer in Customer Master):
Problem / Scenario: In Dim_Customer, how do you create a calculated column counting how many total orders that customer has ever placed?
Formula: Total Order Count = COUNTROWS(RELATEDTABLE(Fact_Orders))
Result: 12 orders
Why it works: RELATEDTABLE grabs all matching rows from Fact_Orders for the current customer row, and COUNTROWS tallies them.

Common Mistakes & Limitations

  • Trying to use `RELATED()` between two tables that have no active relationship in the Model View.
  • Using `RELATED()` inside a measure without an iterator; `RELATED()` strictly requires a Row Context.

Keyboard Shortcuts

ActionWindowsMac
View Relationships in ModelCtrl + 3Ctrl + 3
Formula autocomplete for RELATEDType "REL" -> Press TabPress Tab

Pro Tips & Modern Alternatives

  • Inside a measure, you do not need `RELATED()` if you rely on `CALCULATE` and natural filter context propagation.
  • Use `LOOKUPVALUE()` if you need to fetch values between tables that have NO direct relationship.