hedgie
Board Regular
- Joined
- Jun 23, 2004
- Messages
- 174
- Office Version
- 365
- Platform
- Windows
Here is what I have data wise - Note that I am fudging Column G formulas, that is not the issue. What I want to do is find the Max value of Column G for each range of stock prior to the qty being 0 in column F. So in other words in H2 I would want to see 3735. In h7 I want to see 50, in h9 = 5120 and then in h14 =1850. I would like the other cells in column H to remain blank. Then I can sort to find the max cost for each security during the time period we held it. Any thoughts?
Book1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | Date | Name | Side | QTY | Value | Total Shares | Total Cost | ||
2 | 3/1/2021 | ABC | B | 100 | 250 | 100 | 250 | ||
3 | 4/2/2021 | ABC | B | 500 | 1010 | 600 | 1260 | ||
4 | 5/1/2021 | ABC | B | 1000 | 2100 | 1600 | 3360 | ||
5 | 5/15/2021 | ABC | B | 200 | 375 | 1800 | 3735 | ||
6 | 6/22/2021 | ABC | S | 1800 | 3600 | 0 | 0 | ||
7 | 5/1/2021 | XYZ | B | 200 | 50 | 200 | 50 | ||
8 | 4/1/2022 | XYZ | S | 100 | 75 | 100 | 0 | ||
9 | 3/1/2021 | DEF | B | 100 | 1000 | 100 | 1000 | ||
10 | 3/15/2021 | DEF | B | 200 | 2020 | 300 | 3020 | ||
11 | 3/21/2021 | DEF | S | 100 | 950 | 200 | 0 | ||
12 | 4/18/2021 | DEF | B | 200 | 2100 | 400 | 5120 | ||
13 | 12/15/2021 | DEF | S | 400 | 4100 | 0 | 0 | ||
14 | 4/7/2021 | DEF | B | 200 | 1850 | 200 | 1850 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
G2:G11,G13:G14 | G2 | =IF(AND(C2="B",B2=B1),G1+E2,IF(C2="B",E2,0)) |
F2:F14 | F2 | =IF(B2=B1,F1+IF(C2="B",D2,-D2),D2) |