[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • Last Modified:

NPER - (domain error occured)

Hi

Hilare assisted with the creation of a NPER Function that works similar to excel.  

This is the NPER Function

create function NPERTEST(@rate float, @payment float,@capital float)
returns float
as
begin
return log10(@payment/(@payment+@capital*@rate))/log10(1+@rate)
end
go

select dbo.NPER(.203/12, 500, -5000)  ---> returns 11.047592792208778

This works well and I haven't noticed a problem until this morning.  Based on the value of the payment the procedure throws out a domain error occurred

Try this

Select dbo.NPERTEST(.203/12, 75, -5000) - Payment amount is R 75

Your urgent assistance is required

Thanks for your help in advance

Regards
TAZI

0
TAZI
Asked:
TAZI
  • 4
  • 2
1 Solution
 
HilaireCommented:
TAZI, I'm afraid these values are simply not possible ....

Excel fails to get a value too with these parameters
it gives #number instead of a readable value
0
 
TAZIAuthor Commented:
Hi Hilare

Thanks a million for your prompt response.

How would this be handled then.  I didn't test it in Excel, but have been bothered by it all morning.

Basically, the procedure is being used in an Debt Collection Environment. In the example above, the Debtor owes R5000.00 and the interest rate is 20.3%.  If the debtor wants to pay  R 75.00 per month, how would we determine the number of periods then.

The payment amount is dynamic ... one does not know how much the debtor wants to pay.

Thanks for your help in advance
Regards
TAZI
0
 
HilaireCommented:
when (@payment+(@capital*@rate)) is negative,
log10(@payment+(@capital*@rate)) can't be computed
using microsoft's algorithm ...

best I can do is return a default value (eg 0) when a correct NPER can't be computed

create function NPERTEST(@rate float, @payment float,@capital float)
returns float
as
begin
return case  
               when @payment+@capital*@rate < 0 then 0
               else log10(@payment/(@payment+@capital*@rate))/log10(1+@rate)
         end
end
go
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
HilaireCommented:
Yet a default value of 0 might generate more errors if you use this NPER in other calculations,
so maybe another dummy value like 9999999 would be better.

Anyway you'll have to handle this care somewhere in your code and alert the user on the fact that NPER can't be computed with these parameters values
0
 
HilaireCommented:
i meant "handle this case"
0
 
TAZIAuthor Commented:
Hi Hilare

Thank you so much for your help.  

I did the following to overcome the problem. I work out the minimum payment that a debtor can make against his outstanding debt and if the amount that the debtor wants to pay is less then mimimum payment  I know I am going to get an error and return out of the procedure with the minimum value.  I then display this on screen informing the collector that he/she has to capture a value greater then the minimum payment.

Thanks anyway for your help.

It is greately appreciate.

I will assign the 50 points to you .. you deserve it with all the help that you've given me with these procedures.

Thanks
Regards
TAZI
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now