Aggregation calculation in Groups, using a grouped-on value for a table aggregation
Hi,
I may be missing an easy technique to do this, but I have a DataSet with several date fields, and I am trying to group the data based on a single date field into groups by month, and then perform some aggregate calculations for each group. I've been able to do the grouping either by adding a computed column in the DataSet that uses the month floor (ie first of the month) for the date field of interest, or by using the automatic BIRT Interval grouping by month.
What I need to do is to then calculate an aggregation for each month group, but based on the full DataSet and not just the records satisfying the grouping criteria. So say I have a group based on date March 1, 2011, I would like to use this value against the full dataset to calculate how many records contain a date field that is after this date. I can't just use the computed column that I've grouped on because for each record in the calculation, because the value will vary depending on what date field I used to obtain the month floor for grouping. I want to use March 1, 2011 as the date comparison for EACH record, not just those that fall within the March 2011 grouping, and so on for each group within my report.
I tried writing some scripts to set a persistent global variable in the onCreate event hander for the group header, something like:
reportContext.setPersistentGlobalVariable("groupDate",row['groupingDateField'])
but I am getting null values when I try to retrieve the variable in my aggregation calculation:
reportContext.getPersistentGlobalVariable("groupDate")
Also, I put some debugging output in my report, and it appears that the 'groupDate' global variable doesn't get set until after the first report detail row is written out if I set it using the method above in the 'onCreate' event handler of either the group header or detail row. Reading the documentation, I would expect that it would get set if I put the above 'setPersistentGlobalVariable' code in the detail row 'onCreate' event handler and then tried to output it in the same row via a data element set with the expression (reportContext.getPersistentGlobalVariable("groupDate");). This works, however the first row in the output table has a null value, and subsequent rows have the correct value, so the event order is not what I'd expect.
It seems I have an issue with the event handler firing order, and it is difficult to see what order the events are actually firing in. It seems to me that my aggregation function is trying to retrieve the 'groupDate' persistent global variable before it is able to be set, and I don't see which report element 'onCreate' event handler to set it in to avoid this.
Hopefully this makes sense. Is there an easy way to debug event firing when previewing a report? What should I do to get this working. Or, better yet, is there an easier way to use attributes of a group in aggregation calculations (ie begin and end dates in an automatic monthly interval grouping)?
Example data:
ID GroupingDate OtherDate
A1 March 5, 2011 April 11, 2011
A2 March 25, 2011 March 28, 2011
A3 Feb 6, 2011 April 10, 2011
A4 Feb 19, 2011 Feb 29, 2011
If I group on the GroupingDate field by month, I'd like to count which records 'OtherDate' fields occur before the end of the last day of the grouped month. So in the March group, A2 would be counted, A1 would not, etc.
Thanks for any assistance!