Group expression

Hi guys,

Can someone help me to create correct groups that will calculate sum . I'll explain what do I need. I have  javabean datasource List<Holiday> holidays, Holiday bean has properties : HolidayTemplate template, Date startDate, Integer numberOfPassengers.

What I need is to group holidays by HolidayTemplate and when group changes I need sum of fields numberOfPassengers, at the end I need sum of all numberOfPassengers.  Something like this

France ski  15-01-2011(startDate)  15(numberOfPassengers)

France ski  25-01-2011                    25

France  ski  02-02-2011                    10

                                                         50 (sum of group)

Austria ski   16-01-2011                   12

Austria ski   20-01-2011                   16

                                                          28 (sum of group)  


                                                          78(total sum)

I tried to create group named holidaytemplate and to set group expression $F{template}.getId() and to make a variable groupsum with variable expression  $F{numberOfPassengers} which has propert Calculation set to Sum and property Reset type set to Group and Reset group set to holidaytemplate

Thanks

pegishon's picture
Joined: Jun 1 2010 - 7:32am
Last seen: 13 years 4 months ago

4 Answers:

Sounds like you're doing the right thing so far.  What kind of results are you getting when you drag your variable into the group footer band?  I would expect that your subtotals should be working correctly.  Here are a few points:

- Creating a group like this will create an automatic transition every time you get to a result row that has a different value for the group expression, but it won't automatically resort the items by this group expression, so you need to have already sorted the items the way you want in the query (which is probably by this same expression, but not necessarily).

- If you find that the subtotal is working but you don't know how to create a GRAND total to put in the Summary, here's how.  In the report inspector, right-click and Copy the groupSum variable and then right click "Variables" and Paste a new variable.  Rename it to "reportSum" or something like that.  Notice that it is already set up to be the Sum of the ${numberOfPassengers} field.  The only problem is that you don't want it to reset ever, so change the reset type from "Group" to "Report" for this new variable.  Then drag it into the Summary band.

Carl

cbarlow3's picture
14756
Joined: Mar 4 2010 - 8:59am
Last seen: 1 year 6 months ago

Thanks for advice, but I found that problem was that I had two groups. Here's the thing : First I created Report with two groups, first group was dummy with group expression $VREPORT_COUNT second was my holidayTemlate with group expression $F{holidayTemplate.getId()}, but somehow jasper considers second group within the first group. So compiler was reseting my second group for each new record, and then I put my holidayTemplate as first group and I got what I wanted (I hope I explained well). Now I have another question as far as I understand It matters the way I add groups ? Is it possible to have groups that are mutually idenpendent? It seems that when I create first group every other group is sub group of the first one I created.

    Google
     Custom Search
  1.  

pegishon's picture
Joined: Jun 1 2010 - 7:32am
Last seen: 13 years 4 months ago

I guess I don't understand the purpose of your dummy group, so it's difficult for me to imagine why you would want to define groups independently of each other.  Groups are very Linnean in concept--if you're a different Phylum, then it's automatically implied that you must be a different Class, Order, Family, etc.  If you're a different Family, it's implied that you're a different Genus and Species.  Each Group you define is specifying a level of hierarchy.  If you find that you've defined them in a different order than you mean to (you come up with a new one; you forgot one; you just defined them bottom to top instead of top to bottom, etc.), I believe you can just drag a group up or down the Report Inspector tree to the right level.

Carl

cbarlow3's picture
14756
Joined: Mar 4 2010 - 8:59am
Last seen: 1 year 6 months ago

Thanks for reply and explanation!

pegishon's picture
Joined: Jun 1 2010 - 7:32am
Last seen: 13 years 4 months ago
Feedback
randomness