For cleansing purposes when soaps are used, they form an insoluble precipitate in hard water. This is known as the hardness of the water.
The sulphates, carbonates, and bicarbonate salts of Magnesium and Calcium are insoluble in water and cause hardness.
Thus for cleansing purposes in hard water detergents are a better choice than soaps, as they will not form such insoluble salts with Magnesium and Calcium.