Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2006
    Posts
    73

    Exclamation Unanswered: creating a percentage but getting division by 0 error

    Hey all..

    I'm trying to set up a formula that will allow me to get a percentage between two totals..but my problem is, when I try to get the percentage difference between them I get a division by 0 error..yes I know you can't divide by 0..but this is the if statement I'm using..


    iif ({CUST_ORDER_LINE.UNIT_PRICE}= 0.00 AND {@Order Cost} = 0.00, 0.00, 1-({@Cost}/{@Order Cost}))

    just wondering if I'm doing this correct or if I'm messin up somewhere...any help would be great!

    Thanks in advance

  2. #2
    Join Date
    Dec 2004
    Location
    Connecticut
    Posts
    85
    Are you sure that the problem is with this formula and not in the @Cost formula?

    With your current formula, both Unit Price - which I assume is a component of @Cost - and Order Cost have to be 0 to display 0.00. Since it doesn't matter what the numerator is, do you really need to evaluate the Unit Price?

    iif ({@Order Cost} = 0.00, 0.00, 1-({@Cost}/{@Order Cost}))

    should work if the formula for @Cost returns a value.

  3. #3
    Join Date
    Mar 2006
    Posts
    73
    the @Order Cost is the one that returns a 0, the Cost is a sum of a set of other fields that will never equal 0.

    I'm still getting that error as well..it's not forcing the report to just place a 0.00 in the field..or am I totally missing that part in that statement?

  4. #4
    Join Date
    Dec 2004
    Location
    Connecticut
    Posts
    85
    What happens if you turn the if statement around? Instead of

    if A is true, then do B, else do C

    make it

    if A is false, then do C, else do B

    Like this:

    iif({CUST_ORDER_LINE.UNIT_PRICE}<> 0.00 AND {@Order Cost} <> 0.00, 1-({@Cost}/{@Order Cost}), 0.00)

    If that still gets you nowhere, start by creating an if statement that just returns one of two constants. When you know the if statement behaves as expected, (it returns the right constant if the conditions are met), build up the formula one piece at a time. You'll be able to tell exactly what part of the if statement causes the error.

Posting Permissions

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