There are some decent general techniques for handling this, but I'm still not clear on the logic you want to implement.
For the Identifier ending in 792, for example, the image you attached explains that you want 2 N-COs counted as occurring until completion, but both the CreatedDate and CompletedDate for those 2 N-COs are August 12 2016, which is after the completion date for the COMP, which is August 11 2016.
In your most recent sample data set, you also include rows with a completed date months before the created date.
We really will need the logic you want to implement specified more clearly, along with consistent sample data and desired results to help much. Also, as John pointed out, if you don't have any clear business logic around handling the ties, you'll have to be prepared to accept erratic results.
If this is for a real-world problem, my guess is that you won't be able to just change the dates so there aren't ties any more