Forum Discussion

quads08's avatar
quads08
New Member
5 years ago

Paginated Reports DIV/0 Error

Hello everyone , I'm new to power BI report builder and have been able to google most things. However I am stuck here. 

 

I use this expression and it works 99% of the time except when Fields!ID_Last_4_Weeks_Previous_Year_ECNs_.Value is blank. 

 

Is there a way to modify this to capture that error and keep everything else intact?

 

=IIf(Sum(Fields!ID_Last_4_Weeks_Difference_ECNs_.Value) = 0 ,"",Sum(Fields!ID_Last_4_Weeks_Difference_ECNs_.Value/4)/Sum(Fields!ID_Last_4_Weeks_Previous_Year_ECNs_.Value/4))

 

 

7 Replies

  • Hi quads08 

    Always use DIVIDE() to avoid Div by 0 errors.  ANywhere you do division replace it with DIVIDE e.g.

    DIVIDE( DIVIDE( Sum(Fields!ID_Last_4_Weeks_Difference_ECNs_.Value, 4) , DIVIDE( Sum(Fields!ID_Last_4_Weeks_Previous_Year_ECNs_.Value, 4))

    Regards

    Phil

    • quads08's avatar
      quads08
      New Member

      Good morning PhilipTreacy ,

      First off thanks for the quick reply! I tried to use that but it doesn't work. It gave me the following error.workingnot working

       

      The Value expression for the textrun 'Textbox10.Paragraphs[0].TextRuns[0]' has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset.
      ----------------------------
      The definition of the report '' is invalid.
      ----------------------------
      An error occurred during local report processing.

      • KeithRN's avatar
        KeithRN
        New Member

        A draw back with Power BI is that the expression will still try to calculate a value even though the IIF asks it not to.

         

        I believe the answer provided by Philip is for DAX in Power BI Dashbord reports i.e. Power BI Desktop. As I understand it, in your case, you are using Power BI Report Builder (SSRS for the old folks) to build a paginated report. 

         

        Power BI Report Builder has no built in Divide function. However, you can create one.

        1. With your report opened in Power BI Report Builder, right click on the dark grey area surronding your report and choose Report Properties from the context menu. This will display the Report Properties dialog box.
        2. On the Report Properties dialog box, click the Code tab. This will display the Custom code textbox.
        3. In the Custom code textbox, enter the following function declaration:
        Public Function Divide(ByVal Numerator As Double, ByVal Denominator As Double, ByVal AltResult As Double) AS Double
        If IsNothing(Denominator) Or Denominator = 0
        Return AltResult
        Else
        Return Numerator/Denominator
        End If
        End Function

        Once this is created, you can call it in your Expression like this:

        =IIf(Sum(Fields!ID_Last_4_Weeks_Difference_ECNs_.Value) = 0, "", 
        code.Divide(Sum(Fields!ID_Last_4_Weeks_Difference_ECNs_.Value/4),
        Sum(Fields!ID_Last_4_Weeks_Previous_Year_ECNs_.Value/4), 0))

        Notes:

        1. When calling the function, you must put "code" before your function name.
        2. The function call is saying, if zero is the Denominator, return zero as the result. You can supply any alternative number you want (e.g. -1).
        3. I am assuming that the issue is that the second SUM in the division (the denominator) is causing the issue. Zero as the numerator should return zero.
        4. Multiple functions can be created in the Custom code field. Just add the latest code to the top or bottom of the field.
        5. This is not verified code, so anyone is welcome to improve it.

        I hope this helps someone.

  • v-jingzhang's avatar
    v-jingzhang
    Icon for Community Support rankCommunity Support

    Hi quads08 

    Have you solved this problem? If not, can you share some dummy data so that I can use it to find possible solutions? Thank you.

     

    Regards,
    Community Support Team _ Jing

  • Kindly Check here you are comparing Integer value with your decimal value. SO first convert your field to Integer and then compare with 0

    For e.g.  iif(CInt(Fields!YourValue) = 0, Nothing,Fields!Valu1 / Fields!YourValue)

     

    Enjoy !