Jasper reports 抑制组中的重复值
我有一份有两个波段的报告:Jasper reports 抑制组中的重复值,jasper-reports,Jasper Reports,我有一份有两个波段的报告: 用于显示Group=N的行的详细信息标注栏,即如果为Group N,则该标注栏将隐藏 组页脚,用于显示组=Y的行的集合,即如果组为Y,则隐藏该行 两个标注栏都显示日期、名称和金额。组页脚聚合“金额”字段。 我想禁止重复日期 例如,给定以下数据: +------------+------+-------+--------+ | Date | Name | Group | Amount | +------------+------+-------+------
+------------+------+-------+--------+
| Date | Name | Group | Amount |
+------------+------+-------+--------+
| 2020-06-01 | A | Y | 5 |
| 2020-06-01 | A | Y | 10 |
| 2020-06-01 | D | N | 2 |
| 2020-06-01 | Z | Y | 4 |
| 2020-06-02 | B | N | 1 |
| 2020-06-02 | G | Y | 6 |
| 2020-06-02 | G | Y | 3 |
+------------+------+-------+--------+
它应该显示:
+------------+------+--------+
| Date | Name | Amount |
+------------+------+--------+
| 2020-06-01 | A | 15 |
| | D | 2 |
| | Z | 4 |
| 2020-06-02 | B | 1 |
| | G | 9 |
+------------+------+--------+
使用isPrintRepeatedValues=“false”,它可以复制日期,因为它们位于不同的波段:
+------------+------+--------+
| Date | Name | Amount |
+------------+------+--------+
| 2020-06-01 | A | 15 |
| 2020-06-01 | D | 2 |
| | Z | 4 |
| 2020-06-02 | B | 1 |
| 2020-06-02 | G | 9 |
+------------+------+--------+
添加一个:
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
2020-06-01应显示在第一行中,但在上面的行中,DateGroup_计数值表示聚合带中的最后一行,因此不应显示日期字段时,日期字段将被抑制
注意,上述内容可能在单个频带中实现。它代表了一个报告的简化版本,无法使用单个波段实现,因为它:
- 计算每个波段中不同的金额列
- 在每个波段中有不同的字段,需要有选择地显示/隐藏这些字段。这些也会重叠
Date,Name,Group,Amount
2020-06-01,A,Y,5
2020-06-01,A,Y,10
2020-06-01,D,N,2
2020-06-01,Z,Y,4
2020-06-02,B,N,1
2020-06-02,G,Y,6
2020-06-02,G,Y,3
JRXML
<?xml version="1.0" encoding="UTF-8"?>
<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="duplicatetest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="Aggregate" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="Aggregate">
<groupExpression><![CDATA[$F{Group}]]></groupExpression>
<groupFooter>
<band height="30">
<printWhenExpression><![CDATA[EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField evaluationTime="Group" evaluationGroup="DateGroup" pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup">
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textElement>
<paragraph lineSpacing="Fixed"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="134" y="0" width="116" height="30"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[DateGroup_COUNT]]></text>
</staticText>
<staticText>
<reportElement x="390" y="0" width="68" height="30"/>
<text><![CDATA[Group]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[!EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField evaluationTime="Group" evaluationGroup="DateGroup" pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup">
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
如果我正确理解任务,您只需创建两个组并显示第二组的总数 您可以通过5个步骤解决此任务:
日期
和名称
字段对数据进行排序日期
字段名称
字段Name
我使用printweenexpression属性只显示每个日期
和名称
组的第一条记录的数据。在这个技巧的帮助下,我删除了所有的“副本”
在isRemoveLineWhenBlank=“true”
属性的帮助下,我隐藏了所有空行(对于案例$V{nameGroup\u COUNT}>1
)
最后一个技巧是为具有总和的textField设置evaluationTime=“Auto”
属性
输出结果
生成的报告在JSS中如下所示:
如果我正确理解任务,您只需创建两个组并显示第二组的总数 您可以通过5个步骤解决此任务:
日期
和名称
字段对数据进行排序日期
字段名称
字段Name
我使用printweenexpression属性只显示每个日期
和名称
组的第一条记录的数据。在这个技巧的帮助下,我删除了所有的“副本”
在isRemoveLineWhenBlank=“true”
属性的帮助下,我隐藏了所有空行(对于c
Date,Name,Group,Amount
2020-06-01,A,Y,5
2020-06-01,A,Y,10
2020-06-01,D,N,2
2020-06-01,Z,Y,4
2020-06-02,B,N,1
2020-06-02,G,Y,6
2020-06-02,G,Y,3
<?xml version="1.0" encoding="UTF-8"?>
<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="duplicatetest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="Aggregate" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="Aggregate">
<groupExpression><![CDATA[$F{Group}]]></groupExpression>
<groupFooter>
<band height="30">
<printWhenExpression><![CDATA[EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField evaluationTime="Group" evaluationGroup="DateGroup" pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup">
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textElement>
<paragraph lineSpacing="Fixed"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="134" y="0" width="116" height="30"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[DateGroup_COUNT]]></text>
</staticText>
<staticText>
<reportElement x="390" y="0" width="68" height="30"/>
<text><![CDATA[Group]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[!EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField evaluationTime="Group" evaluationGroup="DateGroup" pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup">
<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
<?xml version="1.0" encoding="UTF-8"?>
<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="duplicatetest" pageWidth="390" pageHeight="842" columnWidth="350" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<sortField name="Date"/>
<sortField name="Name"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="nameGroup" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<group name="dateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="nameGroup">
<groupExpression><![CDATA[$F{Name}]]></groupExpression>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="130" y="0" width="120" height="30"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="250" y="0" width="100" height="30"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField pattern="yyyy-MM-dd">
<reportElement x="0" y="0" width="130" height="30">
<printWhenExpression><![CDATA[$V{dateGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="130" y="0" width="120" height="30">
<printWhenExpression><![CDATA[$V{nameGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField evaluationTime="Auto">
<reportElement x="250" y="0" width="100" height="30">
<printWhenExpression><![CDATA[$V{nameGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
<?xml version="1.0" encoding="UTF-8"?>
<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="duplicatetest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="04479c0d-d012-45d8-a8d1-f281276aba62">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datasuppressiontestdata"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="Date" class="java.util.Date"/>
<field name="Name" class="java.lang.String"/>
<field name="Group" class="java.lang.String"/>
<field name="Amount" class="java.math.BigDecimal"/>
<variable name="groupTotal" class="java.math.BigDecimal" resetType="Group" resetGroup="Aggregate" calculation="Sum">
<variableExpression><![CDATA[$F{Amount}]]></variableExpression>
</variable>
<variable name="COUNT_GROUP_1" class="java.lang.Integer" resetType="Group" resetGroup="DateGroup" incrementType="Group" incrementGroup="DateGroup">
<variableExpression><![CDATA[( $V{Aggregate_COUNT} == 1) ? $V{COUNT_GROUP_1} + 1 : $V{COUNT_GROUP_1}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="DateGroup">
<groupExpression><![CDATA[$F{Date}]]></groupExpression>
</group>
<group name="Aggregate">
<groupExpression><![CDATA[$F{Group}]]></groupExpression>
<groupFooter>
<band height="30">
<printWhenExpression><![CDATA[EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup" uuid="16819840-1496-42ac-aec8-02e50a104608">
<printWhenExpression><![CDATA[$V{COUNT_GROUP_1}==1]]></printWhenExpression>
</reportElement>
<textElement>
<paragraph lineSpacing="Fixed"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30" uuid="5008a25a-6654-4ffc-95dd-cdefac6b1c3a"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30" uuid="c89330be-7a7b-4721-b881-10e5df8ced68"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{groupTotal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30" uuid="5dd2909c-4ffb-4296-9a42-3656bed378fe"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30" uuid="61b8eb92-90ec-4727-a69c-642f063f08fe"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="130" height="30" uuid="f05195da-f90c-4026-9e38-89a902853871"/>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement x="134" y="0" width="116" height="30" uuid="2d40f4cc-a795-4e67-9fac-7a6e77085de3"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="260" y="0" width="100" height="30" uuid="e5c44c50-93da-45a0-8a21-18fab3295972"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="458" y="0" width="100" height="30" uuid="1b22596b-22e0-4b22-b2ab-9ed699ddd61f"/>
<textElement textAlignment="Right"/>
<text><![CDATA[DateGroup_COUNT]]></text>
</staticText>
<staticText>
<reportElement x="390" y="0" width="68" height="30" uuid="8210e103-4473-4a5e-a915-a568356f76ac"/>
<text><![CDATA[Group]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[!EQUALS($F{Group}, "Y")]]></printWhenExpression>
<textField pattern="yyyy-MM-dd">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="30" printWhenGroupChanges="DateGroup" uuid="9112a549-c2e1-4b49-996e-d12f5f1307cf">
<printWhenExpression><![CDATA[$V{COUNT_GROUP_1}==1]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="134" y="0" width="116" height="30" uuid="111ee635-3426-4a2b-8f68-3e4e6dc003c3"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="260" y="0" width="100" height="30" uuid="c0eac89a-54ac-4480-9fa1-3c841aed7d89"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="458" y="0" width="100" height="30" uuid="b2ff7aaf-ab81-4b3d-a45f-9094044af7bf"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$V{DateGroup_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="389" y="0" width="68" height="30" uuid="5ac47f28-41e3-4940-bcdb-91b2ba85f30b"/>
<textFieldExpression><![CDATA[$F{Group}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>