Divide bu 0 error when using report items

Anonymous
2022-09-08T16:37:14.17+00:00

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,798 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,566 Reputation points
    2022-09-09T03:19:14.073+00:00

    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  
    Else  
      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:
    Design:

    239250-05.png

    239289-06.png

    Preview:

    239275-07.png

    Then we test the ReportItems with custom code:

    239208-reportitems.png

    Using Report Items:

    239300-09.png

    Preview again:

    239290-10.png
    Best Regards,
    Joy


    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 40,741 Reputation points
    2022-09-09T07:12:02.883+00:00

    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)  
    
    0 comments No comments