Remaining quantity and cumulative receipt quantity in PO receipt status report(BAQ)

Hello everyone,

I’m trying to create the PO receipt status report in BAQ as shown below.
Except for the two columns, I was able to easily create other columns using DB fields.
The two columns are Balance Qty and Accumulated Qty at the time of the receipt. This is because Balance Qty and Accumulated Qty are continuously updated to the latest, not at the time of receipt.

  • Balance Qty : Remaining quantity of the relevant PO line (Part) (after the relevant receipt)

    I created SQL as “PODetail.OrderQty - PORel.ArrivedQty”, but because ArrivedQty is updated to the latest, Balance Qty at the time of receipt does not appear.

  • Accumulated Qty : Cumulative (immediately before the relevant receipt) receipt quantity of the relevant PO line (Part)

    I created the SQL as “Remain - PORel.ArrivedQty”, but since Remain is updated to the latest, the Accumulated Qty before the Receipt point is wrong.

Can anyone please tell me the SQL to solve this issue?
I would really appreciate it if you could let me know.