user2901955
user2901955

Reputation: 103

#Error shown in RDLC Report

I am trying to do calculation by using expression.

In fact I have the formula to validate whether the report items that used to calculate is 0, this is because if both report items is 0, they not allowed to divided. So if both of the report items is 0, then 0.00 will be assigned to the column instead of process the calculation.

This is my expression which still show #Error in the report column even I have do IIf:

=IIf((ReportItems!TotalQty.Value = "0.000" And ReportItems!Textbox40.Value = "0.000"),  ReportItems!Textbox6.Value="0.00", FormatNumber((ReportItems!TotalQty.Value / ReportItems!Textbox40.Value * 100), 2))

enter image description here

*ReportItems!Textbox40.value is Grandtotal for TotalQty

Do anyone know any way to correct this error.

Please help and guide. Thanks in advance.

Upvotes: 0

Views: 2298

Answers (1)

Przemo.
Przemo.

Reputation: 11

  1. If TextBox40.Value = 0 then "else" value of IIf() function will always #Error (because dividing by zero). I used Val() function to compare your value to zero, not to text. If the TextBox40.Value is equal "abc" or " " (space) or "" (empty string) then Val(TextBox40.Value) is zero too.
  2. 2nd and 3rd arguments of IIf() function are results depending of 1st argument, your 2nd argument looks wrong.
  3. IIf() function calculates all arguments before returns a result, so the 3rd argument (where may be dividing by zero), can give you #Error in result. Better is use If() function.
  4. Better than use FormatNumber() function is formatting of field in Tablix -- the code is clearer.

The expression should be (imho)

=If(Val(ReportItems!Textbox40.Value) = 0,  
    0.00, 
    Val(ReportItems!TotalQty.Value) / Val(ReportItems!Textbox40.Value) * 100
   )

Upvotes: 1

Related Questions