I've discovered that if I groupe by only the necessary columns it filters correctly. I little bit weird. I was hoping to upload the file directly, but cannot do that. I'll put it in Google Drive and share it.
It would be much better to include a reprex with data reduced to the parts that produce the issue you are seeing. Even if you do upload the data you still should post a reprex.
You said it is not working "as expected". How did it work and what specifically did you expect? The reprex is the best way to do this.
A prose description isn't sufficient, you also need to make a simple reprex that:
Builds the input data you are using.
The function you are trying to write, even if it doesn't work.
Usage of the function you are trying to write, even if it doesn't work.
Builds the output data you want the function to produce.
You can learn more about reprex's here:
Right now the is an issue with the version of reprex that is in CRAN so you should download it directly from github.
Until CRAN catches up with the latest version install reprex with
devtools::install_github("tidyverse/reprex")
We ask for a reprex because that is the quickest and easiest way for us to help you. Almost everyone here is answering questions in their spare time and anything you can do to reduce the time it takes to answer your question is appreciated.