jasper报告措施中的交叉表条件

时间:2016-05-10 09:27:13

标签: jasper-reports crosstab

我在JasperSoft studio 6.2工作

这是一个简单的报告,其中包含一个交叉表(来自真实问题的模拟)。我想在度量中添加一个条件,这样当货币为gbp时,val应该乘以3.但这似乎没有发生,该度量只显示val而不管货币。

这是报告现在显示的内容:

enter image description here

c1和r2处的单元格应为3,c2处的单元格和r2

措施的表达

    $F{currency} == "gbp"? $F{val}*3 : $F{val}

数据集查询

    select 'c1' as cg,  'r1' as rg, 1 as val, 'aud' as currency
    union all select 'c1' as cg,  'r2' as rg, 1 as val, 'gbp' as currency
    union all select 'c2' as cg,  'r1' as rg, 1 as val, 'aud' as currency
    union all select 'c2' as cg,  'r2' as rg, 1 as val, 'gbp' as currency

报告:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
    <!-- 2016-05-10T10:19:28 -->
    <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="test6" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="472d0a21-f9e0-4b4c-8830-53ce76baca95">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
        <style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <queryString>
            <![CDATA[select 'c1' as cg,  'r1' as rg, 1 as val, 'aud' as currency
    union all select 'c1' as cg,  'r2' as rg, 1 as val, 'gbp' as currency
    union all select 'c2' as cg,  'r1' as rg, 1 as val, 'aud' as currency
    union all select 'c2' as cg,  'r2' as rg, 1 as val, 'gbp' as currency]]>
        </queryString>
        <field name="cg" class="java.lang.String"/>
        <field name="rg" class="java.lang.String"/>
        <field name="val" class="java.lang.Integer"/>
        <field name="currency" class="java.lang.String"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <summary>
            <band height="220" splitType="Stretch">
                <crosstab>
                    <reportElement x="0" y="20" width="555" height="200" uuid="db69b441-d09f-49f7-b290-7eec7275eb1b">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    </reportElement>
                    <rowGroup name="rg1" width="60" totalPosition="End">
                        <bucket class="java.lang.String">
                            <bucketExpression><![CDATA[$F{rg}]]></bucketExpression>
                        </bucket>
                        <crosstabRowHeader>
                            <cellContents mode="Opaque" style="Crosstab_CH">
                                <textField>
                                    <reportElement x="0" y="0" width="60" height="20" uuid="6f2b3dc8-ae54-4dd9-b74d-8f708dfe0e52"/>
                                    <textFieldExpression><![CDATA[$V{rg1}]]></textFieldExpression>
                                </textField>
                            </cellContents>
                        </crosstabRowHeader>
                        <crosstabTotalRowHeader>
                            <cellContents mode="Opaque" style="Crosstab_CT">
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="23c06ac5-0336-4dec-a4f1-6a9e48d9b470"/>
                                    <text><![CDATA[Total rg1]]></text>
                                </staticText>
                            </cellContents>
                        </crosstabTotalRowHeader>
                    </rowGroup>
                    <columnGroup name="cg1" height="20" totalPosition="End">
                        <bucket class="java.lang.String">
                            <bucketExpression><![CDATA[$F{cg}]]></bucketExpression>
                        </bucket>
                        <crosstabColumnHeader>
                            <cellContents mode="Opaque" style="Crosstab_CH">
                                <textField>
                                    <reportElement x="0" y="0" width="60" height="20" uuid="9872abc3-cac8-4b20-8dac-8f3d294d6c0d"/>
                                    <textFieldExpression><![CDATA[$V{cg1}]]></textFieldExpression>
                                </textField>
                            </cellContents>
                        </crosstabColumnHeader>
                        <crosstabTotalColumnHeader>
                            <cellContents mode="Opaque" style="Crosstab_CT">
                                <staticText>
                                    <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="fc087f0f-321d-46eb-b4ac-44eea96ff044"/>
                                    <text><![CDATA[Total cg1]]></text>
                                </staticText>
                            </cellContents>
                        </crosstabTotalColumnHeader>
                    </columnGroup>
                    <measure name="val_MEASURE1" class="java.lang.Integer" calculation="Sum">
                        <measureExpression><![CDATA[$F{currency} == "gbp"? $F{val}*3 : $F{val}]]></measureExpression>
                    </measure>
                    <crosstabCell width="60" height="20">
                        <cellContents mode="Opaque" style="Crosstab_CD">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" uuid="827bc665-96dc-4adc-9a75-e4549d146d79"/>
                                <textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                    <crosstabCell width="60" height="20" columnTotalGroup="cg1">
                        <cellContents mode="Opaque" style="Crosstab_CT">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="4d85b6d3-b844-4072-aa29-d33559efd678"/>
                                <textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                    <crosstabCell width="60" height="20" rowTotalGroup="rg1">
                        <cellContents mode="Opaque" style="Crosstab_CT">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="f83e2d2f-ad1f-47e7-ac36-567f47862219"/>
                                <textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                    <crosstabCell width="60" height="20" rowTotalGroup="rg1" columnTotalGroup="cg1">
                        <cellContents mode="Opaque" style="Crosstab_CT">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="668927e0-801e-415d-ab82-36040ad4f830"/>
                                <textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
                            </textField>
                        </cellContents>
                    </crosstabCell>
                </crosstab>
            </band>
        </summary>
    </jasperReport>

1 个答案:

答案 0 :(得分:0)

$ F {currency} .equals(“gbp”)? $ F {val} * 3:$ F {val}

您可以搜索==和.equals之间的差异。

相关问题