If your doctor suggested it, then it makes sense to get your levels checked. It's not pure marketing - magnesium really does matter for muscles, nerves and energy - but the thing is, most people get enough of it from food if they eat decently. Leafy greens, nuts, whole grains, fish... there's plenty of it around. That said, fatigue can come from actual deficiencies, stress, poor sleep, a thousand things, so getting checked is the right move before throwing money at supplements.
In the pharmacy, magnesium supplements don't cost a fortune, it depends on the brand and form. We're talking 5-15 euros for a pack that lasts about a month. If the test says you're actually deficient, then the supplement can help you, but it's not magic - it might take weeks before you notice a difference. If your levels are normal though, you save the money and look for what's causing the fatigue elsewhere.
The smartest thing is: get tested by your doctor, blood work or whatever's needed, and decide based on the results. Don't just buy supplements hoping they'll work. And honestly, if the deficiency is mild, it's often more useful to fix your diet than take pills - at least you'll eat better overall.