The kidneys regulate the serum magnesium. About 2400 mg of magnesium passes through the kidneys daily, of which 5% (120 mg) is excreted through urine. The loop of Henle is the major site for magnesium homeostasis, and 60% is reabsorbed. Magnesium homeostasis comprises three systems: kidney, small intestine, and bone. In the acute phase of magnesium deficiency there is an increase in absorption in the distal small intestine and tubular resorption in the kidneys. When this condition persists, serum magnesium drops and is corrected with magnesium from bone tissue. The level of intracellular magnesium is controlled through the reservoir in bone tissue. Diagnosis
Magnesium deficiency is not easy to directly measure. Typically the diagnosis is based on finding low blood magnesium levels (hypomagnesemia). Specifically by finding a plasma magnesium concentration of less than 0.6 mmol/L (1.46 mg/dL). Severe disease generally has a level of less than 0.50 mmol/L (1.25 mg/dL).Magnesium deficiency (or depletion) refers to low total body levels of magnesium which is usually determined by finding low blood levels (hypomagnesemia). Hypomagnesemia refers only to blood levels of magnesium. Either of magnesium deficiency and hypomagnesemia can be present without the other. Electrocardiogram
The electrocardiogram (ECG) change may show a tachycardia with a prolonged QT interval. Other changes may include prolonged PR interval, ST segment depression, flipped T waves, and long QRS duration. Treatments
Treatment of hypomagnesemia depends on the degree of deficiency and the clinical effects.
Metabolic abnormalities
Insufficient selenium, vitamin D or sunlight exposure, or vitamin B6. Gastrointestinal causes: the distal digestive tract secretes high levels of magnesium. Therefore, secretory diarrhea can cause hypomagnesemia. Thus, Crohns disease, ulcerative colitis, Whipples disease and celiac sprue can all cause hypomagnesemia. Postobstructive diuresis, diuretic phase of acute tubular necrosis (ATN) and kidney transplant. Other
Acute myocardial infarction: within the first 48 hours after a heart attack, 80% of patients have hypomagnesemia. This could be the result of an intracellular shift because of an increase in catecholamines. Malabsorption
Acute pancreatitis
Fluoride poisoning
Massive transfusion (MT) is a lifesaving treatment of hemorrhagic shock, but can be associated with significant complications. Pathophysiology
Magnesium is a co-factor in over 300 functions in the body regulating many kinds of  biochemical reactions. It is involved in protein synthesis, muscle and nerve functioning, bone development, energy production, the maintenance of normal heart rhythm, and the regulation of glucose and blood pressure, among other important roles. Low magnesium intake over time can increase the risk of illnesses, including high blood pressure and heart disease, diabetes mellitus type 2, osteoporosis, and migraines.There is a direct effect on sodium (Na), potassium (K), and calcium (Ca) channels. Magnesium has several effects:

Potassium
Potassium channel efflux is inhibited by magnesium. Thus hypomagnesemia results in an increased excretion of potassium in kidney, resulting in a hypokalaemia.