The elements of same group are placed in same group as they have similar properties. So Calcium is the element which resembles Mangesium.
Calcium and Magnesium both are alkaline earth metals.
They have similar properties as they have similar outer or valence shell electronic configuration
The general electronic configuration of alkaline earht metal is ns2
The electronic configuration of Mg [atomic number 12] and Ca [atomic number 20] are
and
respectively.