Dr. Brownstein recommends:
400 mg Magnesium - PM best=glycinate, citrate or malate others are poorly absorbed - more may be needed - See this link - (Calcium will purge magnesium)
You might be taking the wrong kind of magnesium, or you may be taking too much.
Try a different form of magnesium, your body may not respond to the form you are taking.