Forum Discussion

Power_It_Up's avatar
Power_It_Up
Helper II
1 year ago
Solved

Create separate table from 3 tables

Hi.    I have 3 tables which all have a one-to-many relationship. I want to be able to create another table based of different fields from the others.   I've tried many different ways including u...
  • Hakuna_matata's avatar
    1 year ago

    Hi Power_It_Up , There are many reasons why the Related() might not be working but a general example to using the same with your problem statement will be:

    Let’s say you have these three tables:

    Customer (one)

    Order (many, related to Customer)

    Order detail (many, related to Order)

    You want a new table with:
    CustomerName, OrderDate, ProductName

    Here’s how you might do it:

    NewTable =
    SELECTCOLUMNS (
    ADDCOLUMNS (
    OrderDetails,
    "CustomerName", RELATED (Customers[CustomerName]),
    "OrderDate", RELATED (Orders[OrderDate]),
    "ProductName", OrderDetails[ProductName]
    ),
    "CustomerName", [CustomerName],
    "OrderDate", [OrderDate],
    "ProductName", [ProductName]
    )

     

    Double-check your relationships in the model:

    Customer[ID]→Order[CustomerID]

    Order[ID]→OrderDetails[OrderID]

    Also, Making sure you're using Related() in a table that is on the many side of the relationship (to pull from the one side).

    Hope it help! Please mark this as a solution if this is helpful. To better understand please share an example pbix.