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 / Location | Required Operation | Function to Use | Result 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:
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.
Product Category Name = RELATED(Dim_Product[CategoryName])
Column: A column from the related table on the "One" side of the active relationship.
Unit Margin = Fact_Sales[UnitPrice] - RELATED(Dim_Product[WholesaleCost])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.
Customer Lifetime Orders = COUNTROWS(RELATEDTABLE(Fact_Orders))
Table: The related table on the "Many" side of an active relationship.
Total Order Count = COUNTROWS(RELATEDTABLE(Fact_Orders))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
| Action | Windows | Mac |
|---|---|---|
| View Relationships in Model | Ctrl + 3 | Ctrl + 3 |
| Formula autocomplete for RELATED | Type "REL" -> Press Tab | Press 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.