Many people express gratitude to Hashem for being saved from problematic situations. But they would prefer for the problem or difficulty not to have arisen in the first place. This, however, is not the proper attitude.
The purpose of all problems is that they should serve as a means for a person to become closer to Hashem. Both the problems and solutions are part of the divine plan to help elevate you. ~ R’ Yeruchem Levovitz zt”l