I have this data and I want in iReport is group this by number group and color group.

color | number_group | color_group | red | 1 | primary | blue | 1 | primary | yellow| 2 | primary | orange| 2 | secondary | violet| 1 | secondary | green | 1 | secondary | 

I want in my report

Color Group: Primary Number: 1 red blue Color Group: Primary Number: 2 yellow Color Group: Secondary Number: 1 violet green Color Group: Secondary Number: 2 orange 

But in I can only manage to do Add Group > Group Criteria > Group by following expression > choose color_group field.

And the output is this which is not the one that I'm hoping for.

Color Group: Primary Number: 1 red blue yellow Color Group: Secondary Number: 2 orange violet green 

I think the right solution is using Add Group > Group Criteria > Group by following expression > group expression with text area but I don't know what to put there. Anyone?

2 Answers

Group on the concatenation of the two values:

<groupExpression><![CDATA[$F{number_group} + $F{color_group}]]></groupExpression> 

Example

<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="" xmlns:xsi="" xsi:schemaLocation=" " name="group" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c1d9b4b7-6162-4b17-b871-3cf3b867d1ef"> <queryString> <![CDATA[]]> </queryString> <field name="color"/> <field name="number_group"/> <field name="color_group"/> <group name="myGroup"> <groupExpression><![CDATA[$F{number_group} + $F{color_group}]]></groupExpression> <groupHeader> <band height="20"> <textField> <reportElement mode="Transparent" x="0" y="0" width="300" height="20" forecolor="#3333FF" uuid="b3f3381f-26c1-48d5-953e-ddd017fbf7cf"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA["Color Group: " + $F{color_group} + " Number: " + $F{number_group}]]></textFieldExpression> </textField> </band> </groupHeader> </group> <detail> <band height="15" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="300" height="15" uuid="7337168a-363f-4438-a38e-e4859fb6fdd1"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{color}]]></textFieldExpression> </textField> </band> </detail> </jasperReport> 

Output

Result

Note: The get exact same order as your expected output the orange record need to be last (order data)

1

I think nesting 2groups solves this issue.

1st. Add Group > Group Criteria > Group by following expression > choose color_group

2nd. Add Group > Group Criteria > Group by following expression > choose number_group

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.