The molar mass of $Mg(OH)_2$ is $58.3$ $gmol^-1$. The formula mass contains one mole of $Mg$ $(24.3$ $gmol^-1)$ and two moles each of $O$ $(16$ $gmol^-1)$ and hydrogen $H$ $(1$ $gmol^-1)$.
That means the percentages of each element are:
%Mg = $24.3/58.3xx100 = 41.7$ %
%O = $(2xx16)/58.3xx100=54.9$ %
%H = $(2xx1)/58.3xx100=3.4$ %
These percentages add to 100%.
The mass of magnesium in $97.4$ $g$ of $Mg(OH)_2$ is $41.7$ % pf $97.4 = 40.6$ $g$.