I have this problem. I want to compute the following integral in terms of $z$, where $x = az$
$$ \frac{d}{da}\int a^2x^2dx $$
Computing the integral first, the derivative as the last passage, I obtain what I believe to be the correct solution, i.e.,
$$ \frac{d}{da}\int a^2x^2dx = \frac{d}{da}\left(a^2 \frac{x^3}{3}\right) = \frac{d}{da}\left(a^2 \frac{a^3z^3}{3} + c\right) = 5a^4\frac{z^3}{3} $$
and the same by substituting first in the integral, keeping in mind that $dx = a dz$,
$$ \frac{d}{da}\int a^2x^2dx = \frac{d}{da}\int a^2(az)^2 adz \frac{d}{da}\int a^5z^2 dz = \frac{d}{da}\left(a^5 \frac{z^3}{3}\right) = 5a^4\frac{z^3}{3}. $$
Things start to get messy when I take the derivative inside the integral, i.e.,
$$ \frac{d}{da}\int a^2x^2dx = \int 2ax^2dx = \int 2a a^2z^2 adz = 2a^4\frac{z^3}{3}. $$
One might argue that I need to keep in consideration also of $d/da x$, since $x$ depends on $a$, after all. However, I still obtain a wrong result
$$ \frac{d}{da}\int a^2x^2dx = \int a^2 \frac{d}{da}\left(x^2\right) + 2a x^2 dx = \int \left( a^2 \frac{d}{da}\left(a^2z^2\right) + 2a a^2z^2 \right)adz \\ = \int 2a^4z^2 + 2a^4z^2dz = 4a^4\frac{z^3}{3}. $$
Since I am obtaining three different results, I must be making at least two different mistakes; I wonder where these mistakes are. (sorry for being lazy and not including the constant $c$ from the integrals)
We substitute $x=az$ right from the beginning and obtain \begin{align*} \color{blue}{\frac{d}{da}\int a^2x^2dx}&=\frac{d}{da}\int a^2(az)^2d(az)\\ &=\frac{d}{da}\left(a^5\int z^2 dz\right)\tag{1}\\ &=\left(\int z^2 dz\right)\left(\frac{d}{da} a^5\right)\tag{2}\\ &\,\,\color{blue}{=\left(\frac{1}{3}z^3+C\right)\left(5a^4\right)}\tag{3}\\ \end{align*}
Comment:
In (1) we use $d(az)=adz$ and factor out $a$.
In (2) we factor out the constant part.
In (3) we integrate and differentiate.
We are now ready to do the differentiation with respect to $a$ before the integration. To better see what's going on we write $x=x(z,a)$ and $x_z(z,a)$ instead of $x^{\prime}(z)$ to indicate that we differentiate with respect to $z$.