Divide bu 0 error when using report items

Jannette Jones 161 Reputation points

I have a wxpression in and SSRS report that uses report Items and i get an error when running the report can some one help me deal with the divide by 0 error.
=ReportItems!Textbox41.Value / Fields!mnypotientalRentTotal.Value

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,258 questions
No comments
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,381 Reputation points Microsoft Employee

    Hi @Jannette Jones ,
    You can add a function to your report code that handles the divide by zero condition, this makes it a bit easier to implement in multiple cells(Note:This solution also applies to reportitems), e.g.

    Public Function Divider (ByVal Dividend As Double, ByVal Divisor As Double)  
    If IsNothing(Divisor) Or Divisor = 0  
      Return 0  
      Return Dividend/Divisor  
    End If  
    End Function   

    You can then call this in a cell like so:

    =Code.Divider(Fields!FieldA.Value, Fields!FieldB.Value)  

    Here is my test:





    Then we test the ReportItems with custom code:


    Using Report Items:


    Preview again:

    Best Regards,

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 27,306 Reputation points

    me deal with the divide by 0 error.

    The much easier way is to use a case condition using IIF function in your expression to check on zero, like

    =IIF(Fields!mnypotientalRentTotal.Value = 0, 0, ReportItems!Textbox41.Value / Fields!mnypotientalRentTotal.Value)