Magnesium plays an important role in helping vitamin D work properly in the body. While it doesn’t replace vitamin D, it acts like a helper that makes sure vitamin D can do its job well. Vitamin D needs to be changed into active forms in the liver and kidneys,