0

Consider the following table.

Column1   Column2    Column3   Column4
Eric      RoomA      Group1      5
Eric      RoomA      Group1      1
Eric      RoomA      Group1      7
Eric      RoomA      Group2      1
Eric      RoomA      Group2      2
Eric      RoomB      Group1      1
Eric      RoomB      Group1      3
Eric      RoomB      Group2      4

Now based on above dataset, I need to create a jasper report that displays result in following format. I am using a Jasper Table to display the result.

   Column1    Column2     Column3    Column4
   Eric       RoomA       Group1     13
                          Group2     3
   Eric       RoomB       Group1     4
                          Group2     4

Here Column4 is the sum of that column based on values of Column1, Column2 and Column3 as described in below image.

enter image description here

I tried doing the following:

1.Created a variable sum as shown in figure enter image description here

2.Placed that variable in Column4. 3.Created Group "Column1Column2".

<group name="Column1Column2">
        <groupExpression>
             <![CDATA[$F{Column1}+"|"+$F{Column2}]]>
         </groupExpression>
   </group>
  1. Created Group "Column1Column2Column3".

    <group name="Column1Column2Column3">
           <groupExpression>
               <![CDATA[$F{Column1}+"|"+$F{Column2}+"|"+$F{Column3}]]>
            </groupExpression>
     </group>
    
  2. For textfield at Column1 and Column2, print when expression is set to $V{Column1Column2_COUNT}==1 and for textfield at Column3, print when expression is set to $V{Column1Column2Column3_COUNT}==1

The final result is something like this

Column1    Column2     Column3    Column4
 Eric       RoomA       Group1     5
                                   6
                                   13
                        Group2     1
                                   3
 Eric       RoomB       Group1     1
                                   4
                        Group2     4

As you can see the final result is not what is desired. Please, how do I make those unwanted value at column4 disappear?

Edit:

Checked out the duplicate question. This one is different than the other one since my rows are not merged together but rather skipped totally.

ntstha
  • 1,187
  • 4
  • 23
  • 41

0 Answers0