In the wikipedia page on dimensional analysis, an example is given about the period of a harmonic oscillator. The rough idea of the argument is:
We have the following variables and dimensions, written as $\text{variable} [\text{dimension}]$:
$$t [T]; m [M]; k [M/T^2]; \text{ and } g [L/T^2]$$
We want to write $t$ as a function of $m,k,g$. But since $g$ is the only variable that has $L$ in it's dimension, we cannot cancel the $L$ to get dimension $T$. Hence $t$ cannot depend on $g$. The only formula for $t$ in terms of $m$ and $k$ that has dimension $T$, is $c\cdot\sqrt{\frac m k}$. Hence $t=c\cdot\sqrt{\frac m k}$ for some dimensionless constant $c$.
I am confused by this idea for the following reason: Why does $c$ have to be dimensionless? If we allow for dimensionful constants $c$, then we can pick many more relations between $t,m,k$, and pick the dimension of $c$ in order to make the dimensions match. E.g. if we let $c$ have dimension $\frac {M^2} T$, then we can let $t=c\cdot \frac 1 {m\cdot k}$
So given that we can always just add dimensionful constants to an equation, how is it possible that dimensional analysis gives us any information about the relation between physical quantities?
Let $t \propto m^{\alpha} k^{\beta} g^{\gamma}$, then the dimensions on each side must match, so substituting in the units. $$[T] \propto [M]^{\alpha + \beta}T^{-2\beta - 2\gamma}[L]^{\gamma}$$ so we have that $\gamma = 0$, $\alpha = -\beta$, and $\beta = -1/2$, hence $$ t \propto \sqrt{\frac{m}{k}}, $$ with some constant of proportionality. This exponent method is usually how I approach dimensional analysis. If there were some other dimensions on the right hand side they would have appeared from this method. I also recommend looking at the Buckingham $\pi$ theorem.