The other factor in this equation is pH. Magnesium set the relationship between the alk and Ca. Alk and Ca set the pH. If your magnesium is right, this allows your alk and Ca to be right which puts your pH where it should be.
This, of course, is a very simplified explanation. Actual water...