条件和(变量)

Lap*_*404 2 jasper-reports ireport

iReport(4.0.1)中包含各种字段的报告包括:( $F{value}整数)和$F{created_at}.

我想计算可以给出的变量:

  1. $F{value}何时$F{created_at}在给定日期之前的总和
  2. $F{value}何时$F{created_at}在给定日期之后的总和

知道如何做到这一点?

Aar*_*ron 7

您将不得不使用两个不同的变量来执行此操作.对于您的变量,请在"变量表达式"中使用类似的内容.Date类还有一个after()函数.如果表达式求值为true,则将添加$ F {value},否则将添加0.

$ F {created_at} .before($ P {givenDate})?$ F {值}:0

要使用变量求和,需要将计算类型更改为"Sum".默认的重置类型,报告将对整个报告中的值进行求和.其他重置类型在报表的不同部分(列,页面或组)上的工作方式相同.

以下是"之前"案例的XML:

<variable name="sumValueCreatedBefore" class="java.lang.Integer" calculation="Sum"> <variableExpression><![CDATA[F{created_at}.before($P{givenDate}) ? $F{value} : 0]]></variableExpression> </variable>