在SSRS表达式中删除嵌套iif中的NaN

时间:2016-09-13 12:43:56

标签: reporting-services expression nan iif

SQL-SSRS新手

如何向以下代码添加功能以将返回的NaN值更改为0或空白?我认为正在发生的情况是,同意和不同意的总和= 0我得到这个楠。我认为如果我不处理同意和不同意的类别,这对我来说会更容易。同样,SQL编程的新手。任何帮助将不胜感激。

<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-5 col-md-offset-1">
        <h3>MAIN TITLE</h3>
      </div>
    </div>
    <div class="row">
      <div class="col-md-offset-1 col-md-5 col-xs-12">
        <div class="card horizontal">
          <div class="card-image">
            <img src="https://upload.wikimedia.org/wikipedia/en/thumb/f/ff/Morning_Glory_Flower_square.jpg/1024px-Morning_Glory_Flower_square.jpg">
          </div>
          <div class="card-stacked">
            <div class="card-content">
              <h3>Title Goes Here</h3>
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,  sed doeiusmod tempor incididunt.</p>
              <button class="btn btn-styled">START COPY</button>
             </div>
           </div>
         </div>
      </div>

      <div class="col-md-offset-1 col-md-5 col-xs-12">
        <div class="card horizontal">
          <div class="card-image">
            <img src="https://upload.wikimedia.org/wikipedia/en/thumb/f/ff/Morning_Glory_Flower_square.jpg/1024px-Morning_Glory_Flower_square.jpg">
          </div>
          <div class="card-stacked">
            <div class="card-content">
              <h3>Title Goes Here</h3>
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,  sed doeiusmod tempor incididunt.</p>
              <button class="btn btn-styled">START COPY</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

3 个答案:

答案 0 :(得分:0)

尝试以下内容,

=Replace((Sum(IIF(Fields!Response.Value = "Agreed",Fields!Days.Value,0)) + 
Sum(IIF(Fields!Response.Value = "Disagreed",Fields!Days.Value,0))),"NaN","0")
/ Replace((Sum(IIF(Fields!Response.Value = "Agreed",Fields!Fq.Value,0)) 
+ Sum(IIF(Fields!Response.Value = "Disagreed",Fields!Fq.Value,0))),"NaN","0")

另外,请查看this

答案 1 :(得分:0)

您应该在表达式中处理DIV 0问题,而不是将从除以0返回的文本替换为:

=IIF(
    SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Fq.Value, 0)) = 0, 0, 
        SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Days.Value, 0)))
/IIF(
    SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Fq.Value, 0)) = 0, 1, 
        SUM(IIF(Fields!Response.Value = "Agreed" OR Fields!Response.Value = "Disagreed", Fields!Fq.Value, 0)))

如果SUM为,则计算为 0/1 ,否则为 SUM(天)/ SUM(Fq),其中回复是同意不同意

而不是两个总和,只需在一个中使用OR。

答案 2 :(得分:0)

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 

此功能使您可以编写自定义代码来修复Nan的所有问题。 这可以通过以下方式调用

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

您的代码如下

=Code.Divider(((Sum(iif(Fields!Response.Value = "Agreed",Fields!Days.Value,0)) + Sum(iif(Fields!Response.Value = "Disagreed",Fields!Days.Value,0))), ((Sum(iif(Fields!Response.Value = "Agreed",Fields!Fq.Value,0)) + Sum(iif(Fields!Response.Value = "Disagreed",Fields!Fq.Value,0)))))