Please wait
Talk to Expert
Microsoft Dynamics 365, Microsoft Dynamics Business central, Microsoft Dynamics NAV

Handling Division by Zero in RDLC Reports with Business Central

Feature Image_ Division By Zero In RDLC Reports.

Handling Division by Zero in RDLC Reports with Business Central

To handle division by zero in RDLC reports in Business Central and multiply the result by 100, you can use custom code within the report. Here’s how you can achieve this:

1. Open your RDLC report with Report Builder.

2. Right Click & Navigate to the Report properties.

3. Click on the “Code” tab.

4. Enter the following function:

Shared Denominator as Decimal

Shared Numerator as Decimal

Public Function DivideByZero(ByVal Numerator As Decimal,

ByVal Denominator As Decimal) As Decimal

     If Denominator = 0 Then

           Return 0

     Else

            Return (Numerator / Denominator) * 100

      End If

  End Function

5. Save the code.

Now, you can use this custom code function `DivideByZero` in expressions within your report to handle division by zero cases and multiply the result by 100. For example, if you have a textbox expression where you want to use this function, you can write something like this:

=Code.DivideByZero(Fields!Numerator.Value, Fields!Denominator.Value)

Replace `Fields!Numerator.Value` and `Fields!Denominator.Value` with the appropriate field names from your dataset.

This expression will call the custom function we defined earlier, passing the numerator and denominator values as parameters, and it will return the result of the division multiplied by 100 if the denominator is not zero. If the denominator is zero, it will return 0 to avoid division by zero error.

Remember, error handling isn’t just about preventing crashes; it’s about fostering trust in your application’s reliability and usability. With careful planning and implementation, you can elevate the quality of your reports and deliver value to users within the Business Central environment.


Comments