Forum Discussion

Diogo_Dalla's avatar
Diogo_Dalla
Frequent Visitor
4 years ago
Solved

Join with Clauses

Hi, I am looking for a way to merge two tables adding some clauses to the join.   For example: Scrap Table:   Order Step Quantity Scrapped Cost 1234 3 1 37   Order table: O...
  • v-kkf-msft's avatar
    v-kkf-msft
    4 years ago

    Hi Diogo_Dalla ,

     

    Please try the following measure or custom column(PQ).

     

    Measure:

    SumCost = 
    SUMX (
        SUMMARIZE (
            Scrap,
            Scrap[Order],
            "_sum",
                CALCULATE (
                    SUM ( 'Order'[Cost] ),
                    FILTER (
                        'Order',
                        'Order'[Step] <= MAX ( Scrap[Step] )
                            && 'Order'[Order] = MAX ( 'Scrap'[Order] )
                    )
                )
        ),
        [_sum]
    )

     

    PQ Column:

    JoinOrderCost =
    let 
       myfunction = (CurrentOrder, CurrentStep) => 
         let 
           SelectRows = Table.SelectRows(Order, each [Order] = CurrentOrder and [Step] <= CurrentStep) 
         in 
           SelectRows,
       Data = List.Sum( myfunction([Order],[Step])[Cost])
    in 
       Data

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.