Hi all!
I have a table with Commercial Conditions and start and end dates.
Sometimes, new condition begin before the end date of previous condition, and I need to be able to find it and correct an end date of a previous condition. (the end date is the start date of next row of same condition minus 1 day)
Date format here mm-dd-yyyy:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]row index[/TD]
[TD]ID[/TD]
[TD]Start Date[/TD]
[TD]End Date[/TD]
[TD]Actual End date (to be calculated by formula)[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ID1[/TD]
[TD]01-01-2014[/TD]
[TD]10-20-2049[/TD]
[TD]03-19-2014 (03-20-2014 minus 1 day)[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ID2[/TD]
[TD]04-01-2015[/TD]
[TD]01-01-2020[/TD]
[TD]01-01-2020[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]ID3[/TD]
[TD]06-01-2014[/TD]
[TD]07-01-2014[/TD]
[TD]07-01-2014[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]ID1[/TD]
[TD]03-20-2014[/TD]
[TD]10-10-2015[/TD]
[TD]04-30-2014 (05-01-2014 minus 1 day)[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]ID1[/TD]
[TD]05-01-2014[/TD]
[TD]01-01-2019[/TD]
[TD]01-01-2019[/TD]
[/TR]
</tbody>[/TABLE]
So, in that case, a formula in right column row 1 shall find all rows with same ID (row 1, 4, 5), check that end date of current row (10-20-2049) is greater than start date of next closest start date (03-20-2014), and select that date minus 1 day as a new end date (03-19-2014).
Similar in row 4: the formula shall find all same IDs (row 1, 4, 5), check that end date of current row (10-10-2015) is greater than start date of next closest start date (05-01-2014), and select that date minus 1 day as a new end date (04-30-2014).
In row 5: the formula shall find all same IDs (row 1, 4, 5), check that there are no next closest start dates, and return the end date of row 5.
Please help me to do that.
Thanks!
I have a table with Commercial Conditions and start and end dates.
Sometimes, new condition begin before the end date of previous condition, and I need to be able to find it and correct an end date of a previous condition. (the end date is the start date of next row of same condition minus 1 day)
Date format here mm-dd-yyyy:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]row index[/TD]
[TD]ID[/TD]
[TD]Start Date[/TD]
[TD]End Date[/TD]
[TD]Actual End date (to be calculated by formula)[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ID1[/TD]
[TD]01-01-2014[/TD]
[TD]10-20-2049[/TD]
[TD]03-19-2014 (03-20-2014 minus 1 day)[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ID2[/TD]
[TD]04-01-2015[/TD]
[TD]01-01-2020[/TD]
[TD]01-01-2020[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]ID3[/TD]
[TD]06-01-2014[/TD]
[TD]07-01-2014[/TD]
[TD]07-01-2014[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]ID1[/TD]
[TD]03-20-2014[/TD]
[TD]10-10-2015[/TD]
[TD]04-30-2014 (05-01-2014 minus 1 day)[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]ID1[/TD]
[TD]05-01-2014[/TD]
[TD]01-01-2019[/TD]
[TD]01-01-2019[/TD]
[/TR]
</tbody>[/TABLE]
So, in that case, a formula in right column row 1 shall find all rows with same ID (row 1, 4, 5), check that end date of current row (10-20-2049) is greater than start date of next closest start date (03-20-2014), and select that date minus 1 day as a new end date (03-19-2014).
Similar in row 4: the formula shall find all same IDs (row 1, 4, 5), check that end date of current row (10-10-2015) is greater than start date of next closest start date (05-01-2014), and select that date minus 1 day as a new end date (04-30-2014).
In row 5: the formula shall find all same IDs (row 1, 4, 5), check that there are no next closest start dates, and return the end date of row 5.
Please help me to do that.
Thanks!