CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2015
    Posts
    2

    Crystal Report Division by zero error

    I am trying to replace an embedded summary field with a formula - so I can sort on the field. I am taking the variance amount and dividing it by the budget amount to come up with a variance percent.
    Here are several formulas I have tried without success. I either get a 'division by zero' error or invalid data.

    if isNull(@Budget) Then 0
    Else (@Variance) / (@Budget)
    *******
    evaluateafter(@Variance);
    if(@budget)<> 0 Then
    (@variance) / (budget)
    else 0
    *******
    evaluateafter(budget);
    if (variance) <> 0 then
    if(budget) <>0
    then (variance) / (budget)
    else 0

    thanks in advance for any help provided.

  2. #2
    Join Date
    Aug 2007
    Posts
    179

    Re: Crystal Report Division by zero error

    Hello,
    I suggest your testing on the divisors does not cover all possible values. In your first example you test for a null divisor, but not a zero value divisor. In the next 2 examples you test for zero, but not null.

    If IsNull(@Budget) Then 0
    Else If (@Budget) = 0 Then 0
    Else (@Variance / @Budget)

  3. #3
    Join Date
    May 2015
    Posts
    2

    Re: Crystal Report Division by zero error

    Hi Ned,

    That makes sense; however, when I changed my formula to your suggested one, I now get large numbers for the variance percent.

    Here's an example:

    Budget Variance Variance % (should be) Formula (this is what I get now)
    278.7 (15.5) (5.6) 2,941
    92.1 (14.3) (15.5) 2,666

  4. #4
    Join Date
    Aug 2007
    Posts
    179

    Re: Crystal Report Division by zero error

    Hello,
    The values you are seeing are not related to the testing for a null and/or zero divisor. That test simply allows the division to take place. You will need to examine your data, and your @Variance and @Budget formulas to determine why you are not getting the desired results.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured