What to do when you reach a conclusion and find out later on that someone else already did?
Do not despair: your work likely still has value!

In my experience, it's almost never the case that work addressing the same problem has exactly the same solution or exactly the same approach to gathering evidence.  Existence of a previous publication will thus typically make your results smaller and more incremental, but not invalid or duplicative.  Some examples of what your work may provide:


A second, independent confirmation of a hypothesis
Confirmation of a closely related but different hypothesis
A different approach that has advantages in some situations and disadvantages in others


There are even good journals like PLOS ONE that explicitly invite replications and "non-notable" incremental work.  Thus, if you've got a set of results in hand and you discover somebody else has done much the same, you should still write up your work---just be straight and honest about the smaller size of contribution based on the prior work.

If you're still at the "ideation" stage where you're just thinking up possible work to do, however, then it seems more appropriate to move on and work on something else instead---maybe building on their results.