Forum Discussion

hasanhilmi's avatar
hasanhilmi
Frequent Visitor
3 years ago
Solved

Calculating Purchase Quantities under Purchase Agreement

Hi everyone! New to the board and excited to learn.    I have two tables,  PurchaseAgreement and PurchaseOrderTransactions. What I want is to sum the purchase quantities I have generated under each...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi hasanhilmi ,

     

    Here I suggest you to create a calculated column by this code.

    Quantity = 
    CALCULATE (
        SUM ( PurchaseOrderTransactions[Quantity] ),
        FILTER (
            PurchaseOrderTransactions,
            PurchaseOrderTransactions[Vendor] = EARLIER ( PurchaseAgreement[Vendor] )
                && PurchaseOrderTransactions[Item] = EARLIER ( PurchaseAgreement[Item] )
                && PurchaseOrderTransactions[Warehouse] = EARLIER ( PurchaseAgreement[Warehouse] )
                && AND (
                    PurchaseOrderTransactions[DeliveryDate]
                        >= EARLIER ( PurchaseAgreement[StartDate] ),
                    PurchaseOrderTransactions[DeliveryDate]
                        <= EARLIER ( PurchaseAgreement[EndDate] )
                )
        )
    )

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.