We present probability distribution functions (PDFs) of the surface densities of ionized and neutral gas in the nearby spiral galaxies M31 and M51, as well as of dust emission and extinction Av in M31. The PDFs are close to lognormal and those for HI and Av in M31 are nearly identical. However, the PDFs for H2 are wider than the HI PDFs and the M51 PDFs have larger dispersions than those for M31. We use a simple model to determine how the PDFs are changed by variations in the line-of-sight (LOS) pathlength L through the gas, telescope resolution and the volume filling factor of the gas, f_v. In each of these cases the dispersion sigma of the lognormal PDF depends on the variable with a negative power law. We also derive PDFs of mean LOS volume densities of gas components in M31 and M51. Combining these with the volume density PDFs for different components of the ISM in the Milky Way (MW), we find that sigma decreases with increasing length L with an exponent of -0.76 +/- 0.06, which is steeper than expected. We show that the difference is due to variations in f_v. As f_v is similar in M31, M51 and the MW, the density structure in the gas in these galaxies must be similar. Finally, we demonstrate that an increase in f_v with increasing distance to the Galactic plane explains the decrease in sigma with latitude of the PDFs of emission measure and FUV emission observed for the MW.