The formula for an ionic compound is called a formula unit, which is the lowest whole-number ratio of ions in the compound, which also makes it an empirical formula. This is because ionic compounds do consist of individual molecules.
The overall charge of an ionic compound must be zero. So the sum of the positive and negative ions must equal zero.
The formula for the aluminum cation is Al3+, and the formula for the phosphate anion is PO3−4.
So the formula unit for aluminum phosphate represents a 1:1 ratio of aluminum and phosphate ions, which is represented as AlPO4