#Error in SSRS report

Jannette Jones 161 Reputation points
2022-11-18T20:26:12.51+00:00

So i have a expression that calculates the variance percentage but when i run the report i get a #ERROR.
The equation is = = iif(Fields!mnyGPITotal.Value=0,"",Fields!Varriance.Value

/iif(Fields!mnyGPITotal.Value=0,1,Fields!mnyGPITotal.Value))

Not sure how i can fix this.

262032-2022-11-18-12-25-20.png

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

1 answer

Sort by: Most helpful
  1. Joyzhao-MSFT 15,471 Reputation points Microsoft Employee
    2022-11-21T06:59:34.33+00:00

    Hi @Jannette Jones ,
    Please try:

    =IIF((Fields!mnyGPITotal.Value = 0 or Fields!mnyGPITotal.Value  is nothing), "", Fields!Varriance.value/IIF(Fields!mnyGPITotal.Value = 0 or Fields!mnyGPITotal.Value is nothing, 1,( Fields!mnyGPITotal.Value)))  
    

    Or:

    =IIF((Fields!mnyGPITotal.Value = 0), "", Fields!Varriance.value/IIF(Fields!mnyGPITotal.Value = 0, 1,( Fields!mnyGPITotal.Value)))  
    

    Or you can add a function in your custom code to handle division by zero:

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

    then call it in a cell like this:

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

    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.

    0 comments No comments