I want to create Variable count in JasperReport

5.1k Views Asked by At

In my report, I have two values of column "Status" are: Y/N. I want to count "Y" in "Status". I created a variable $V{count_y} with Variable Expression : String.valueOf($F{status})=="Y" but $V{count_y} count all record (include Y and N).

<variable name="count_y" class="java.lang.Integer" calculation="Count">
    <variableExpression><![CDATA[String.valueOf($F{status})=="Y"]]></variableExpression>
</variable>

Now, how can i count? Thanks !

1

There are 1 best solutions below

0
On

Create variable like this

<field name="status" class="java.lang.String"/>
<variable name="countY" class="java.lang.Integer" calculation="Sum">
    <variableExpression><![CDATA[$F{status}.equals("Y") ? 1 : 0]]></variableExpression>
</variable>

and put $V{countY} into Summary band