SAP Knowledge Base Article - Public

1213803 - Err Msg: "Division by Zero" when previewing, refreshing, or opening a report

Symptom

  • When previewing, refreshing, exporting or opening a report, the following error message is received in Crystal Reports: "Division by Zero"

Environment

SAP Crystal Reports 2016

SAP Crystal Reports 2020

Cause

 Incorrect logic allowing case with division by zero

Resolution

This error occurs because a formula in the report contains two fields that are being divided (/). One field is divided by another field in a formula and could contain a zero value.

For example:

//@Formula

{Customer.CustomerID}/{Customer.LastYearsSales}

If {Customer.LastYearsSales} contains a zero value the error "Divide by Zero" is received.

You should note that any number can be divided into zero but cannot be divided by zero.

To resolve this error message, create a formula similar to the following that will check for zero values in your data:

NOTE: =====

This formula checks whether a zero value is contained in your data. If a zero value is found, Crystal Reports will produce a zero value in your field allowing the calculation to produce a result and to not return an error.

==========

1. From 'Insert', select 'Field Object'. This launches the 'Field Explorer'.

2. Select 'Formula Fields', and click the 'New' icon in the toolbar.

3. Type a formula name into the 'Formula Name' box. For example, Sales.

4. Click 'OK'. This launches the Crystal Reports formula editor.

5. Create a formula similar to the following:

//@Sales

//The next line assigns a value of zero if the field is equal to zero

if {Customer.Last Years Sales} = 0 then 0

else

//The next line carries out the division if

//{Customer.Last Years Sales} is

//not equal to zero

{Customer.Customer ID} /{Customer.Last Years Sales}

6. Save your formula, and close the formula editor.

Now, when you preview the report you will not receive the error message.

Keywords

DIVISION BY ZERO ERROR FROMULA REFRESG PREVIEW OPEN OPENING REPORT DESIGNER Crystal Reports Formula Errors Division , c2009960 , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , Problem

Product

SAP Crystal Reports 2016 ; SAP Crystal Reports 8.0