The thing is I am finding solution for the below case. Here I wish to find the that orderQ is spread across to how many months.
E.g.
> for the month of February orderQ 55 compares it with Fvalue and I should get the figure in new column as 20 (55-35)
> Again it compares it with next row since the result is positive (20-15) and I should get the figure in new column as 5
> again it compares it with next row since the result is positive (5-2) as 3 and so on.
--> Comparison should not go beyond December
--> In case of comparison coming out to be negative, this logic should not proceed
Problem _
| Code1 | Month | Fvalue | Code2 | orderQ |
| abc123 | January | 49 | | |
| | February | 35 | abc123 | 55 |
| | March | 15 | | |
| | April | 2 | | |
| | May | 16 | abc123 | 15 |
| | June | 10 | abc123 | 34 |
| | July | 12 | | |
| | August | 10 | abc123 | 10 |
| | September | 21 | | |
| | October | 32 | abc123 | 45 |
| | November | 44 | | |
| | December | 16 | | 20 |
| xyz456 | January | 23 | xyz456 | 45 |
| | February | 16 | | |
| | March | 10 | xyz456 | 67 |
| | April | 12 | xyz456 | 67 |
| | May | 10 | | |
| | June | 21 | xyz456 | 56 |
| | July | 32 | | |
| | August | 35 | xyz456 | 34 |
| | September | 15 | xyz456 | 23 |
| | October | 23 | | |
| | November | 12 | | |
| | December | 10 | xyz456 | 23 |
Expected Result
| Code1 | Month | Fvalue | Code2 | orderQ | NewField | Explanation |
| abc123 | January | 49 | | | | |
| | February | 35 | abc123 | 55 | 20 | (55-35) |
| | March | 15 | | | 5 | (20-15) |
| | April | 2 | | | 3 | (5-2) |
| | May | 16 | abc123 | 15 | -1 | (15-16) |
| | June | 10 | abc123 | 34 | 24 | (34-10) |
| | July | 12 | | | 12 | (24-12) |
| | August | 10 | abc123 | 10 | 12 | (12+10-10) |
| | September | 21 | | | -9 | (12-21) |
| | October | 32 | abc123 | 45 | 13 | (45-32) |
| | November | 44 | | | -31 | (13-44) |
| | December | 16 | | 20 | 4 | (20-16) |
| xyz456 | January | 23 | xyz456 | 45 | | |
| | February | 16 | | | | |
| | March | 10 | xyz456 | 67 | | |
| | April | 12 | xyz456 | 67 | | |
| | May | 10 | | | | |
| | June | 21 | xyz456 | 56 | | |
| | July | 32 | | | | |
| | August | 35 | xyz456 | 34 | | |
| | September | 15 | xyz456 | 23 | | |
| | October | 23 | | | | |
| | November | 12 | | | | |
| | December | 10 | xyz456 | 23 | | |
Thanks in advance