The Young's double slit formula is only an approximation ! The approximation is that angle is small then tan (angle) =x/D and sin (angle)= lamda/a are approximately equal. Hence the equation lamda= ax/D.
If you use dsin(angle)=lamda (for n =1) and if angle is small it would be approximately tan(angle) = x/D and hence dx/D =lamda which is ax/D as a is spacing between slits.
It is therefore important to use Young's double slit with caution. In general it is applicable to most questions found with 2 source and a screen a large distance from it.
Link provide a
derivation of young's double slit formula.