Hi there! MgNH4PO4.6H2O has a molecular mass of 245.4065 g/mol while PO4^3- has an MM of 94.9714 g/mol. We can just divide the MM of the phosphate ion to the hydrous compound to find the percentage of phosphate. From that we can now find the mass of the hydrous compound using the 0.31 grams of phosphate.
(0.31g/0.386996)=Total mass of Hydrous Cmpnd
0.80104 g of MgNH4PO4.6H2O