Dear Ksharp, so thanks for your code. But when i add one more day for each id, result is not true. Please remind the 2nd condition "If less than 15 between the day values, then the 2nd value removed". For example: Please add Day 140 for ID=3. 3 48 3 89 3 116 3 127 3 140 When we subtracting 116 from the next value ("127"), the output (11) can't crossing the critical value (15) so it should be delete. Where this row (ID=3 and Day=127) removed from input file, now the last valid day (up to this point is 116) should be subtracting from the next number (refers to the new number "Day=140"). 140-116= 24. You can see that it is more then the critical value, so it should be remained in the output file. zana
... View more