How can I prevent (an error caused by) a division by zero?

In your report layouts you can include expressions that perform a division, e.g.,

[[SalesLine.Amount] / [SalesLine.Quantity]]

For this example, when the Quantity is 0, a division by zero occurs which will lead to a run-time exception that crashes the rendering process.

To avoid this, you can prevent the division by zero as follows:

[[SalesLine.Quantity] != 0 ? ([SalesLine.Amount] / [SalesLine.Quantity]) : 0]

The following expression states: “If the Quantity is not zero, then return the result of the division Amount/Quantity, otherwise if Quantity is zero, then return 0.”

QUESTIONS?
Let us know.