You need to do more for a decent a approximation algorithm like interpolate the last two results and calculate the next IRR and add a treshold value (like 0.0001)
you can solve it by this approach:
$NPV + ($IteratorCashFlow/Amount div pow($Interest, $IteratorCashFlow/Year))
return a decimal$IRR1 - (($NPV1 * ($IRR2 - $IRR1)) div ($NPV2 - $NPV1))
This is the secant method.
Set $IIR1 to the temp var.
Add a decision with
abs($NPV2) < 0.001
if true: solved and return $IIR2 , other wise return to step 5
As as safetynet you can add a loopcounter for exceptions to quit the loop after 100 iterations. Increment the loopcounter.
Make a for-while loop and increase the IRR variable and recalculate until you got a zero result