Let's break this down to cover your two questions individually
Question 1 If a trait would be advantageous to an organism then why hasn't it evolved yet?
This one is really easy, natural selection, as well as other forms of selection, can only work with the variation that arises through mutation. Mutation is a random process evolution has no control about what variation will arise it can only select from those that do. Successful mutations tend to be small changes (small changes are less likely to disrupt a complex process like an organism) because of this organisms can get stuck with disadvantageous setups because evolution cannot go back to drawing board, it cannot go through a disadvantageous change to get an advantageous one.
My classic example is human back problems, a spine is a horrible thing to use to support weight upright but a spine was all evolution had to work with, it was the best option of what was available and being upright was a bigger advantage than the problems with a spine were a disadvantage. Designing a whole new system would be better but the chances of the hundreds of thousands of mutations need to "start over from scratch" are so astronomically unlikely we will never see it. Evolution can only select for the best out of what is available and mutation can only make small changes to what is available.
Another example is the Laryngeal nerve in giraffes which is a 14ft nerve that literally only goes a few inches, but since the nerve evolved when a straight line from the brain to the tongue left the heart in front of it (fish), as terrestrial vertebrates developed necks and moved the heart into the chest the nerve is stuck running down around the heart before returning to the head, a ~14ft detour. having the nerve is a bigger advantage than the detour is a disadvantage, and a mutation redirecting the nerve would be a large complex mutation thus is unlikely to ever occur. A historical legacy like this is responsible for a lot of bad adaptations that stick around, changing them is just too difficult to happen by random mutation.
Question 2 Conversely, if a trait is not advantageous or mildly disadvantageous, why does it exist?
there are a few components to this no trait is advantageous in an of itself, it is advantageous in a particular organism and environment. Sharks beautifully adapted masters of the ocean, drop one in the Sahara and it is doomed. what is good in one environment is often a disadvantage in another. Combine this with the fact that organisms move(or spread) and the fact that environments change and it is easy to see how organisms can end with a mildly disadvantageous adaptation. Adaptations for hunting from the ice was an advantage for polar bears when ice was plentiful now that the ice is disappearing it is not so advantageous. but the ice is disappearing faster than evolution can change the polar bears.
Often the changes in environment are changes in the other organisms around them, being extremely fast is actually a horrible adaptation for gazelle in many ways, it makes them fragile, it makes them small and weaker than other ungulates, it spends calories to grow muscles that could be used to produce larger offspring or taller bodies, etc, but in an environment with cheetah not being fast is a worse disadvantage. In this way, evolution is often about taking the least bad out of a set of bad "choices". And of course, the faster the gazelle get the faster the cheetah get until they are too specialized to live any other way. This push to specialization is very common however specialized organisms are the least able to handle change, they are too specialized to do anything different. So if say a new predator shows up that can force fragile cheetah away from their kills (humans) the cheetah are screwed, they could suffer a huge die off (Africa) or go extinct (North America). Evolution cannot make you good in every direction, you cannot be both a good swimmer and a good climber and a good digger.
Another aspect is cost vs benefit, a trait does not occur in isolation, a body is a complex thing, the same mutation that makes some humans resistant to cholera also makes them more susceptible to cystic fibrosis, this will be an net advantage when cholera is a big threat and a net disadvantage when cholera is rare. they key term here is net there is no condition when it is purely an advantage or disadvantage. Basically, all traits fall into this cost-benefit comparison. No trait is an advantage in every situation, every change has a cost, even if it is just calories that could be spent elsewhere. We know of no traits that are purely a disadvantage that persists but there are many many (if not all of them) such tradeoff traits, a disadvantage for an advantage.
Another example is sexual selection, some traits help you to find or attract mates but are detrimental to your survival, but reproduction is a bigger advantage in evolution than survival. Evolution simply cannot favour genes if they never make it into the next generation consistently. So you end with peacock tails that get the males killed but are the only way to find mates. A male without the huge tail will not mate and the male offspring of a female without the desire for big tails will suffer the same problem (because the female keeps ending up with unattractive male offspring) so it is basically impossible for peacocks males to stop growing huge tails and it is unlikely peacock females will stop preferring bigger and bigger tails. Thus even though it is very detrimental to peacock survival the trait sticks around because it is an advantage in reproduction.