Magnesium plays an important role in carbohydrate metabolism and its deficiency may worsen insulin resistance, a condition that often precedes diabetes, or may be a consequence of insulin resistance.People being treated on an intensive care unit (ICU) who have a low magnesium level may have a higher risk of requiring mechanical ventilation, and death. Causes
Magnesium deficiency may result from gastrointestinal or kidney causes. Gastrointestinal causes include low dietary intake of magnesium, reduced gastrointestinal absorption or increased gastrointestinal loss due to rapid gastrointestinal transits. Kidney causes involve increased excretion of magnesium. Poor dietary intake of magnesium has become an increasingly important factor – many people consume diets high in refined foods such as white bread and polished rice which have been stripped of magnesium-rich plant fiber.Magnesium deficiency is not uncommon in hospitalized patients. Up to 12% of all people admitted to hospital, and as high as 60–65% of people in an intensive care unit, have hypomagnesemia.About 57% of the US population does not meet the US RDA for dietary intake of magnesium. The kidneys are very efficient at maintaining body levels; however, if the diet is deficient, or certain medications such as diuretics or proton pump inhibitors are used, or in chronic alcoholism, levels may drop. Low levels of magnesium in blood may be due to not enough magnesium in the diet, the intestines not absorbing enough magnesium, or the kidneys excreting too much magnesium. Deficiencies may be due to the following conditions:

Medications
Loop and thiazide diuretic use (the most common cause of hypomagnesemia)
Antibiotics (i.e.
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.