PAPERCLIPSANDPAPER
PAPERCLIPSANDPAPER

Reputation: 77

Comparing two columns on a row and removing if they match

I'm looking to create a report in iReport, this will display a row of Car weights which includes there expected weight and actual weight. I'm looking to only display the cars that have are different between the actual weight and expected weight. I'm also looking to display an extra columns on the right which displays how much they're different by.

E.g.

CAR         Expected Weight           ActualWeight           WeightDIFF
-------------------------------------------

> NUGLN9L       2000kg                    2200kg      200kg

> YBOL9GT        1700kg                   1700kg      0kg (Shouldn't display this row)

> CL55GBP        1100kg                   2200kg      1100kg

The part of jrxml:

    <columnHeader>
        <band height="61" splitType="Stretch">
            <textField>
                <reportElement x="108" y="0" width="100" height="20" uuid="205a44be-528a-4d6b-83e7-85cc0f417fd6"/>
                <textFieldExpression><![CDATA[$F{car}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="219" y="0" width="100" height="20" uuid="704e546a-d4f1-4d8d-b5e7-a7ac8154d882"/>
                <textFieldExpression><![CDATA[$F{expectedWeight}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="332" y="0" width="100" height="20" uuid="08846a54-7415-4f32-a0ef-41f2770e2278"/>
                <textFieldExpression><![CDATA[$F{ActualWeight}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="443" y="0" width="100" height="20" uuid="7ebea114-3303-48c0-b877-f0940c62aa7f"/>
                <textFieldExpression><![CDATA[$F{WeightDIFF}]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>

Any help would be excellent

Upvotes: 0

Views: 887

Answers (2)

Dunny774
Dunny774

Reputation: 74

If you are using iReport designer you can select the field on screen, on the right pane of properties each field has a Print When Expression property. You can create a variable (Boolean is easiest). E.G

!$F{CarWeight1}.equals($F{CarWeight2})

Create a variable and set that as a boolean. Drop the variable into the print when expression property on each field. Also worth ticking remove line when blank for each field for formatting purposes.

Hope this helps.

Upvotes: 1

tobi6
tobi6

Reputation: 8239

As @AlexK pointed out, you can use the Print when expression.

After your <band> row, add the following (I assume $F{WeightDIFF} is an Integer):

<printWhenExpression><![CDATA[$F{WeightDIFF} > 0]]></printWhenExpression>

Upvotes: 1

Related Questions