抑制组中的重复值

问题描述 投票:0回答:1

我有两个波段的报告:

  1. 用于显示具有Group = N的行的明细带,即,如果Group <> N,则隐藏它。
  2. [组页脚,用于显示具有Group = Y的行的汇总,即如果Group <> Y,则将其隐藏]]
  3. 两个区域都显示日期,名称和金额。组页脚汇总“金额”字段。我想取消重复的日期。

例如,鉴于以下数据:

+------------+------+-------+--------+
|    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>

并用表达式取消显示日期字段:

<printWhenExpression><![CDATA[$V{DateGroup_COUNT} == 1]]</printWhenExpression>

也不起作用,如下图所示。我包括了Group和DateGroup_Count值用于调试:

+------------+------+--------+-------+-----------------+
|    Date    | Name | Amount | Group | DateGroup_COUNT |
+------------+------+--------+-------+-----------------+
|            | A    |     15 | Y     |               2 |
|            | D    |      2 | N     |               3 |
|            | Z    |      4 | Y     |               4 |
| 2020-06-02 | B    |      1 | N     |               1 |
|            | G    |      9 | Y     |               3 |
+------------+------+--------+-------+-----------------+

2020-06-01应该显示在第一行中,但在上面的DateGroup_COUNT值表示聚合范围中的最后一行,因此,如果不应该显示Date字段,则将其隐藏。

注意,以上可能在单个频带中实现。它代表了报告的简化版本,无法使用单个波段来实现。

用于数据源的CSV:

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

The 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>

我有一个带有2个带的报告:一个明细带,用于显示具有Group = N的行,即如果Group <> N,则被隐藏。一个组脚注,用于显示具有Group = Y的行的聚合,即...

jasper-reports
1个回答
0
投票

据我所知,正确的任务是,您需要创建两个组并显示第二个组的总数。

© www.soinside.com 2019 - 2024. All rights reserved.