Jump to content
We've recently updated our Privacy Statement, available here ×

Evaluate distinct count at the beginning of report


quacker.2715

Recommended Posts

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?

jasper-distinctcount.png.ffbf5d47b3e4121092a8c0cf6b992d9d.png

<?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>
 
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...