everything happens for a reason

proverb
Graduate
1

Used for consolation, possibly self-consolation, after someone has experienced something unfavorable or unpleasant, and hence an encouragement to make the best of the situation.