Summation of values based of on text values

Occasional Contributor

Hello, would like yr assistance in my following requirement . Attached below is my tentative work sheet. My concern is on column L. I have never used this platform before so I will try to explain my requirement as descriptive as possible. 
Every transaction has a (buy open to sell close) or (sell open to buy close) mentioned on column D. Buy open to sell close in this case "buy open" on D12 and "Sell close " on D15 ... and correspondingly I would like to add the K column from k12 to k15 and show it on L15 ...HERE IN OUR CASE the answer is -9750. 

Similarly, I I would like to add from "sell open" to "buy close" in this case "sell open" on D16 and "buy close" is on D18 ...I would like to add corresponding all values between them in the K column from k16 to k18 and show it on this case the answer is -9416 (L18)

in my excel sheet L column I have manually input the numbers ...
Is thr any formula I can use for the L column which can automatically read my requirement and show the transaction wise profit and loss automatically ?

Your help tis greatly appreciated.

2 Replies
best response confirmed by mohammed3786 (Occasional Contributor)

@mohammed3786 Perhaps the solution in the attached workbook will work for you.


Thank you for the prompt reply Riny.
I understood the logic and it works perfectly as intended. Really appreciate it.

Thankyou very much.