"And God sent me before you to preserve you a posterity in the earth, and to save your lives by a great deliverance. So now it was not you that sent me hither, but God: and he hath made me a father to Pharaoh, and lord of all his house, and a ruler throughout all the land of Egypt". Genesis 45:7,8
It wasn't until the end of his trial that he was able to see the whole picture. God had a purpose for Joseph and though it looked like others were "doing it to him", it was God sending him ahead to be in place for the great task of saving His people.
Hindsight is often 20/20 but we don't always have the luxury of living in hindsight. We live in the "here and now". Because of this all we see is what is happening in the present and we judge our circumstances accordingly. Often what we see as bad, from God's perspective He sees it as good. Don't misunderstand, He doesn't call evil good, but He sees the good that He can bring out of it. Yes, the brothers did an evil thing, but God brought great good out of it. Often what we see as a "demotion" God sees as a "promotion". With each new transition-- from his home, into the pit, then into slavery and next into the prison-- Joseph saw demotion. It looked like he was getting further and further away from God's plan. But from God's perspective it was like a steppingstone placing him in the exact position and right place.
Don't get discouraged when things aren't going as you planned. Don't see the negative in it. Don't look at it as a demotion. Don't look at it as just another trying circumstance. Ask the Lord to show it to you from His perspective. You might be surprised because it may actually be bringing you one step closer to fulfilling God's plan.
Have a great day. Don't view your trying circumstances as a defeat or demotion, it may be the next steppingstone that is bringing you into your destiny.