"Supplementation of 500 mg of Mg has been associated with significant improvement in the insomnia severity index, sleep time, sleep efficiency, sleep onset latency, serum cortisol concentration, serum renin, and melatonin"
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5637834/
I'll pit my anecdata against your anecdata: Magnesium supplementation didn't do anything for my insomnia. I used the magnesium glycinate formulation from reputable brands at appropriate dosages.
More: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3703169/ https://www.ncbi.nlm.nih.gov/pubmed/23853635 https://www.ncbi.nlm.nih.gov/pubmed/8232845