Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Select value from another Table for operation.

Hello All,

 

I have two tables as below.Have not listed all the columns in them.I need to get the price from the Price table for each of the part in the Order table and create a new column with that.Merging the tables would work but is there any other way?

Thanks for helping

PartOrderQtyNew Column(QTY*Price
123ABC55
345XYZ612
678PQR721

 

Part Price
1231
3452
6783
2344
5675

 

Thanks

 

  • Hi Anonymous ,

     

    To create a calculated column in Order table as below.

    Column =
    VAR pri =
        CALCULATE (
            MAX ( Price[Price] ),
            FILTER ( Price, Price[Part ] = 'Order'[Part] )
        )
    RETURN
        'Order'[Qty] * pri
    

     

    Pbix as attached.

     

5 Replies

  • v-frfei-msft's avatar
    v-frfei-msft
    Community Support

    Hi Anonymous ,

     

    To create a calculated column in Order table as below.

    Column =
    VAR pri =
        CALCULATE (
            MAX ( Price[Price] ),
            FILTER ( Price, Price[Part ] = 'Order'[Part] )
        )
    RETURN
        'Order'[Qty] * pri
    

     

    Pbix as attached.

     

  • Anonymous assuming you have relationship between these two tables, Part table is on one side of the relationship, you can use expression to add new calculated column in your table

     

    New Column Qty x Price = 
    Table[Qty] * RELATED ( Part[Price] )

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k Thanks.There is a many to many relationship and guess Related does not work well with this relationship as i get error.

      The column  either doesn't exist or doesn't have a relationship to any table available in the current context.

      • parry2k's avatar
        parry2k
        Super User

        Anonymous many to many is surely the issue, not sure why you have many records for a part number in part table.