Once upon a time, there lived an old man on the northern
frontiers of China. One day, his horse disappeared. His neighbors
came to comfort him. But the old man was not at all upset. He said
his loss might turn out to be a good thing. And he was right. A few
months later, not only did his horse find its way back, it also
brought with it another horse, one that was even better. His
neighbors came around again, this time to congratulate him on his
gain. But again, the old man viewed the situation differently, and
said that this "good luck" might bring about misfortune in the end.
Strangely, he was right again. A few days later, his son fell from
the new horse and broke his leg. However, as a result of the
accident, his lame son was not conscripted to fight in the war and
remained with his family.
Nowadays, people refer to the idiom when comforting someone who
has experienced ill fortune. However, although it does imply that
bad luck can sometimes transform into good luck, the reverse is
also true; good luck can sometimes give rise to bad.