Evaluate distinct count at the beginning of report

0

I have been unable to figure out how to show/hide a group header based on group distinct count.  Here is what I have done so far:

  • create a variable - calculation=distinct count; field=group field; reset=report
  • put variable on a detail, set evaluation to report and it is showing 2 (correct value).

However, I am unable to use the distinct count value on detail in print condition.  Is there a way to force the value to be evaluated at the beginning of the report?

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 5.6.1.final using JasperReports Library version 5.6.1  -->
<!-- 2017-06-06T11:54:27 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Evaluate" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a736ce53-7e76-4194-9086-96d2270a6250">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<queryString language="SQL">
<![CDATA[select Company, Acc
from (values ('abc','Account1'),
('abc','Account2'),
('abc','Account3'),
('abc','Account4'),
('abc','Account5'),
('abc','Account6'),
('xyz','Account7'),
('xyz','Account8'),
('xyz','Account9'),
('xyz','Account10'),
('xyz','Account11'),
('xyz','Account12'),
('xyz','Account13')) as a(Company,Acc)]]>
</queryString>
<field name="COMPANY" class="java.lang.String"/>
<field name="ACC" class="java.lang.String"/>
<variable name="companyCount" class="java.lang.Integer" calculation="DistinctCount">
<variableExpression><![CDATA[$F{COMPANY}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="grpCompany">
<groupExpression><![CDATA[$F{COMPANY}]]></groupExpression>
<groupHeader>
<band height="32">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<frame>
<reportElement mode="Transparent" x="0" y="0" width="800" height="14" uuid="a5fce2e6-5f35-402f-ba08-6f9179391631">
<printWhenExpression><![CDATA[$V{companyCount}.compareTo(1) > 0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="227" height="14" forecolor="#FF0000" uuid="ad19fa74-c16c-4357-8160-94f9e743bd5f">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textFieldExpression><![CDATA[msg("{0} Header",$F{COMPANY})]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement mode="Transparent" x="0" y="16" width="800" height="14" uuid="a5fce2e6-5f35-402f-ba08-6f9179391631">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<printWhenExpression><![CDATA[$V{companyCount}.compareTo(1) == 0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="227" height="14" uuid="ad19fa74-c16c-4357-8160-94f9e743bd5f">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textFieldExpression><![CDATA[msg("{0} Header",$F{COMPANY})]]></textFieldExpression>
</textField>
</frame>
</band>
</groupHeader>
<groupFooter>
<band height="32">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<frame>
<reportElement mode="Transparent" x="0" y="0" width="800" height="14" uuid="a5fce2e6-5f35-402f-ba08-6f9179391631">
<printWhenExpression><![CDATA[$V{companyCount}.compareTo(1) > 0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="227" height="14" forecolor="#FF0000" uuid="ad19fa74-c16c-4357-8160-94f9e743bd5f">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textFieldExpression><![CDATA[msg("{0} Footer",$F{COMPANY})]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement mode="Transparent" x="0" y="16" width="800" height="14" uuid="a5fce2e6-5f35-402f-ba08-6f9179391631">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<printWhenExpression><![CDATA[$V{companyCount}.compareTo(1) == 0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="227" height="14" uuid="ad19fa74-c16c-4357-8160-94f9e743bd5f">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textFieldExpression><![CDATA[msg("{0} Footer",$F{COMPANY})]]></textFieldExpression>
</textField>
</frame>
</band>
</groupFooter>
</group>
<detail>
<band height="15" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<frame>
<reportElement key="CSV_EXPORT" mode="Transparent" x="0" y="0" width="800" height="13" uuid="7e787b7d-8fae-466e-9924-e08ade8dffaf"/>
<textField evaluationTime="Band" pattern="">
<reportElement x="20" y="0" width="190" height="12" uuid="71dcc6e8-ebea-4cc5-a3a3-6ba27b17a35b">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font fontName="SansSerif" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$V{companyCount}.compareTo(1) > 0 ? "More than one": "Only One"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="227" y="0" width="100" height="12" uuid="628df114-8f8b-4059-8f7c-d9a62978b157">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$V{companyCount}]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto">
<reportElement x="350" y="0" width="100" height="12" uuid="c4bf9f14-b316-4067-8e2a-c2cc78d31274">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{ACC}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
</jasperReport>
 
quacker.2715's picture
Joined: Jan 12 2017 - 3:26pm
Last seen: 3 years 7 months ago

0 Answers:

No answers yet
Feedback
randomness