I have seen one method which correctly evaluates $P=\frac{2x^2-1}{x(1-x^2)}$.
But I have seen a method that says if $\frac{\frac{\partial M}{\partial y}-\frac{\partial N}{\partial x}}{N}$ is a function of just x ,i.e, it is equal to f(x) then its
Integrating Factor (IF)=$e^{\int f(x)dx}$
Here M=$2x^2y-y-ax^3$ and N=$x(1-x^2)$
So, $\frac{\partial M}{\partial y}=2x^2-1$ and $\frac{\partial N}{\partial x}=1-3x^2$
Hence, $$\frac{\frac{\partial M}{\partial y}-\frac{\partial N}{\partial x}}{N}=\;\;\frac{5x^2-2}{x(1-x^2)}$$
Here's the link to the first method: https://haygot.s3.amazonaws.com/questions/1374381_1134731_ans_55dd44fc75824f228cd5c8286c3144f1.jpg
Please tell why the answer is not matching.
The integrating factor need not to be unique for the non-exact equation $M(x,y)dx+N(x,y)dy=0$. The integrating factor $\mu(x)$ obtained by the method you used may lead to a solution which misses some solution of given ODE or conatin an extra solution (kind of weed) which is not the solution of given ODE. Though in this case, the final solution will be same irrespective of the different $\mu(x)$ obtained in the two methods as it is free from variable $y$.