Ravindra BagaleCourses & study guides मराठी Track your progress

13. DAX: Data Analysis Expressions

13.11 RELATED and RELATEDTABLE in Power BI DAX with Example

RELATED in Power BI DAX with example — in 30 seconds

What: RELATED brings a value from the "one" side table into a row of the "many" side table.

Why: Orders has Qty. Product has Unit Price. Line value needs both on the same row.

Tiny example: BLK-1: 2 × ₹30 = ₹60. Total line value = ₹235.

First look at the data (before → after):

RELATED in Power BI DAX with example: before and after tables, fictional Blinkit Maharashtra data

Same before / after tables as text

Before — Orders (many side)

Order ID Product ID Qty
BLK-1 P-021 2
BLK-2 P-041 1
BLK-3 P-021 3

About this data: This table uses columns: Order ID, Product ID, Qty. This table uses columns: Product ID, Unit Price (₹). This table uses columns: Order ID, Qty, Unit Price, Line Value (₹). Values shown are the lesson examples already on this page (not a new dataset).

Before — Product (one side)

Product ID Unit Price (₹)
P-021 30
P-041 85

Formula / click path

Line Value = Orders[Qty] * RELATED(Product[Unit Price])
(needs an active Product 1 → * Orders relationship)

After — New column in Orders

Order ID Qty Unit Price Line Value (₹)
BLK-1 2 30 60
BLK-2 1 85 85
BLK-3 3 30 90

Do it step by step:

  1. Check the relationship Product[Product ID] 1 → * Orders[Product ID] in Model view.
  2. Select Orders. Table tools › New column.
  3. Type the Line Value formula.
  4. Total of the column = ₹235. In a measure, prefer SUMX(Orders, Orders[Qty] * RELATED(Product[Unit Price])).

Both use existing relationships (संबंध) and are mostly used in calculated columns or iterators.

  • RELATED(<column>) – fetches a value from the one side (lookup, like VLOOKUP). Used on the many side.
  • RELATEDTABLE(<table>) – returns the related rows from the many side. Used on the one side.
-- Calculated column in Orders (many side): bring Category from Product
Category = RELATED(Product[Category])

-- Calculated column in Orders: city of the dark store that served the order
Store City = RELATED(DarkStore[City])

-- Calculated column in Customer (one side): count this customer's order lines
Customer Order Lines = COUNTROWS(RELATEDTABLE(Orders))

-- Calculated column in DeliveryPartner: number of orders delivered by this partner
Partner Orders = CALCULATE(DISTINCTCOUNT(Orders[Order ID]))   -- context transition

LOOKUPVALUE

LOOKUPVALUE(<result column>, <search column>, <search value>) can find a value without a relationship. It is useful occasionally, pan relationships + RELATED are faster and clearer.

Ravindra Bagale's Tip

A common mistake is using RELATED in a measure without a row context, or from the one side of a relationship. RELATED works in calculated columns or inside iterators (SUMX over Orders) on the many side. From the one side, use RELATEDTABLE. Remember this rule.

Loading DAX practice tasks...

  1. Shop city on every sale (Easy): Calculated column on Sales: Shop City = the City of the shop that made the sale.
  2. Shop country on every sale (Easy): Calculated column on Sales: Shop Country = the Country of the related shop.
  3. Line revenue column (Easy): Calculated column on Sales: Line Revenue = Cups × Price.
  4. Is it a Scottish sale? (Medium): Calculated column on Sales: Is Scotland = TRUE when the related shop Country is "Scotland".
  5. Number of sales per shop (Medium): Calculated column on Shop: Sale Count = number of Sales rows for that shop.
  6. Cups per shop (Medium): Calculated column on Shop: Shop Cups = total Cups of the related Sales rows.
  7. Revenue per shop column (Medium): Calculated column on Shop: Shop Revenue = Cups × Price added over the related Sales rows.
  8. London revenue measure (Hard): Measure: London Revenue = Cups × Price added for sales whose shop City is "London". Use FILTER on Sales with RELATED.
  9. England cups with IF (Hard): Measure: England Cups = add Cups only when the related shop Country is "England", else add 0.
  10. Busy shops per city (Hard): Shown per City. Measure: Busy Shops = number of Shop rows whose related Sales count is 6 or more.

Ravi Sir's Cards for this lesson

मराठी cards