I always make sure to make an end goal before I start something or at least before I get too far into it. I've ended up having to scrap a lot of writing and scenes I liked because they didn't fit in with what I managed to come up with for an ending. Also having an ending planned out helps greatly with making sure you're not throwing in a bunch of pointless scenes. "Why is this here?" "Uh, I don't know. I didn't have an idea in mind and was just writing, but it has no general purpose." There's a difference between random scenes with no meaning and happy filler for a break from the main storyline.
When I come up with my endings, I think of my characters and my setting:
For instance, I have a very happy, easy-going mc who loves photography. She lives in a massive city where even different regions have different cultures of people. The South is rich, and the North is desolate after the rich decided to turn the North into a dumpster. I kept racking my brain thinking "Wow, how do I make my mc do something?" I didn't want to have the whole city planned out and do nothing about it. It needed to be fixed! In the end, I finally came up with something.
Personally, I got tired of heroine mcs. I wanted to create someone who was a bit selfless and didn't do something amazing for the greater good but for personal reasons. The mc's adopted brother is a Northerner, so he's surrounded by guilt a lot thinking of how he escaped the horrible living situation that's still there because he lives in the mid-region of the city safe and sound while his people are still suffering. She uses her social media presence with photography to bring more attention to the Northern situation and begins to create connections to solve it. Not because she came to realize it on her own. She even admits if he was never her brother, she would have never looked the North's way. Additionally, helping the North boosts her photography business. She is selfish. Not that she isn't a good person, but she's not super brave. She's an average woman. She's scared when she's scared.
So, I guess in short, my answer is that my ending comes to me after I flesh out some aspects of the story like characters and settings. If your characters don't fit in the setting, the story wouldn't make sense... Like putting James Bond in Blue's Clues or something. It's okay to get into it a little bit, but if you go too far, you might end up having to scrap things you don't want to or making your story a bit complex. Of course, that's just my answer and outlook on it.