Problem Building a logic around getting values from same field
I am having difficult time to figure out a problem. Please see the attach file and below description of the problem.
When a Previous ID is Upgraded or downgraded to Current ID, the Sales Type is either U or D and Sales Price is for the current ID. But the ID which is Previous ID now they were once Current ID and they are included in the current ID and their Sales Type is A. My problem is to get the Downgraded Sales Amount by subtracting the Sales Price Attached to the Current ID from the Sales Price Attached to the Previous ID. For example, The downgraded amount for Current ID 155 is, (157-150) = 7
I am struggling to build the logic for this problem. Can anybody shed some light on it?