A lot depends on size of tank,size and number of fish, size of filter,and how many water changes one is willing to perform.Obviously a twenty gal long for example, would house many more neon tetras than it would giant danios.One must also consider the number of times fish are fed daily, along with how much food is being offered. I don't believe there is a scientific formula although it would be great if there was. One must also consider the growth of the fish. You could keep a couple hundred Tetras in a 80 or 90 gal tank but that same tank would only support possibly two Oscars into adult hood.
Anyhow,, that's my take on the matter.
The most important medication in your fish medicine cabinet is.. Clean water.