Monday, July 2, 2012

Crystal Reports : How to Deal with Zero Divide Errors

When dividing numbers, most commonly to calculate percentages, there is always the risk of a "zero divide" error. That is, you're trying to divide a number by zero. When you force Crystal to do this, the report will halt completely, show no data and scare the willikers out of the end-user with intimidating Formula-based Crystal messages.


The only way to really avoid this issue is to have completely "clean"data (yeah, I know, right?), or to test for this within whatever formula you are using.

Example: The formula field called {frmSalesPerDay} is a simple division of {NumSales} by {NumDays}.

So our {frmSalesPerDay} code should look like this:

if {NumSales} = 0 then 0 else {NumSales} / {NumDays}

So, if {NumSales} equals zero, then we simply return a zero and exit the formula. Otherwise, we let it perform the division.This is a good habit to get into even if your data is clean; you can never anticipate what will happen in the future of the database.

2 comments:

Microsoft Dynamics AX training in Hyderabad said...

Microsoft Dynamics AX training, do keep a few things in mind to get the maximum out of the course as well as the application.we teach Microsoft Dynamics AX training and class at Hyderabad.

Microsoft Dynamics AX training in Hyderabad
Microsoft Dynamics CRM training in Hyderabad
Microsoft Dynamics NAV training in Hyderabad

Microsoft Dynamics CRM training in Hyderabad said...

Microsoft Dynamics CRM training will help you manage and prioritize your business goals, customize.we teach MS Dynamics CRM training and class available at Hyderabad.

Microsoft Dynamics AX online training
Microsoft Dynamics CRM online training
Microsoft Dynamics NAV online training