A urine magnesium test measures the amount of magnesium excreted by the kidneys, which helps assess kidney function and magnesium balance in the body. Increased urinary magnesium levels can indicate conditions such as hypermagnesemia, chronic kidney disease, or high dietary magnesium intake. Low urinary magnesium may be associated with gastrointestinal issues, malnutrition, or certain metabolic disorders. This test is useful for diagnosing electrolyte imbalances and evaluating kidney-related causes of abnormal magnesium levels.