Bug 155090 - Total.runningSum for subgroup
Summary: Total.runningSum for subgroup
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 2.1.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Gary Xue CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
: 173903 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-08-24 14:44 EDT by Vladimir CLA
Modified: 2009-05-27 20:41 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir CLA 2006-08-24 14:44:46 EDT
I have group “MonthGroup” and subgroup “InsuranceGroup”.

I need to calculate total visits of patients in column “year to date” for both group.

For first group (“MonthGroup”) it was easy. 
I just made this expression:
Total.runningSum(row["VisitCount"], null, 0)

But I can’t figure out how to get that for second group (“InsuranceGroup”).

Let say for the first month we have 10 medicaid's patients visits. 
On the second month we got 13 medicaid's patients visits.

In report we need to see something like this:

Month         Total  YTD
-------------------------
January       
  medicaid    10     10 
  medicare    5      5

  total       15     15 
-------------------------
February      
  medicaid    13     23 
  medicare    7      12

  total       20     35 
-------------------------
March         
  medicaid    11     34 
  medicare    6      18

  total       17     52 
-------------------------

I have the following expressions: 

Total By Insurance:  
  Total.Sum(row["VisitCount"], null, "InsuranceGroup")

Total By Month:  
  Total.Sum(row["VisitCount"], null, "InsuranceGroup")

Year To Date Total By Month:
  Total.runningSum(row["VisitCount"], null, 0)

Year To Date Total By Insurance:
  Can't find correct expression!!!

I found some information regarding nested total expressions here:
http://dev.eclipse.org/mhonarc/lists/birt-dev/msg05295.html

But I’m still stuck.

The birt’s documentation is lack of information, how to use “Total.runningSum” function on subgroup level.

In case if exists possibility to calculate Total.runningSum for subgroup please put corresponding information in the manual.
And don't forget describe that to me :)

In case if no way to calculate running sum for subgroup using birt's functions it makes sense to do some improvements for aggregate framework.
Comment 1 Lin Zhu CLA 2006-08-25 09:34:14 EDT
Rather interesting case ;-)

One solution to the problem is that use "filter" in aggregation. Say, Total.runningSum(row["VisitCount"], row["Insurance"]=="medicaid", 0) and 
Total.runningSum(row["VisitCount"], row["Insurance"]=="medicare", 0).

The other solution is to define a computed column using java script in data set's predefined method.Say, we define a computed column "RunningSum", the pseudocode could like follows:

in open method:
---------------------------------------
Map month = new HashMap();
---------------------------------------

in fetch method
---------------------------------------
if( month.get(row["Month"]) == null )
    month.put(row["Month"]);

var tempMap = month.get(row["Month"]);
var count = 1;
if( tempMap.get(row["Insurance"]) == null )
{
    tempMap.put(count);
}else
{
    count = tempMap.get(row["Insurance"]) + 1;
    tempMap.put(row["Insurance"], count);
}

row["RunningSum"] = count;
---------------------------------------

The other solution I can figure out so far is similar to above ones.

These solutions are either incomprehensive or not easy to implement. We will continue investigating.
Comment 2 Vladimir CLA 2006-08-27 00:15:27 EDT
Thank you Lin for trying to provide at least temporary solutions.
I will take your second solution as work around in my report.
You probably will agree with me that group identifier as third argument useless in current implementation of "Total.runningSum" method.
I mean we can use "Total.runningSum" only with group identifier equal to zero.

I suggest to change current implementation of the method such way that defining group identifier will be enough to calculate running sum correctly regarding to selected group. This behavior will be consistent with others aggregate related methods. For example such method as "Total.sum" acting this way. 

Examples: 

Total.runningSum(row["VisitCount"], null, "MonthGroup")
Total.runningSum(row["VisitCount"], null, "InsuranceGroup")

Of course implementation of the method will be more compicated because you have to take into account hierarchy of the groups. You did this in second solution creating the map of month.
Comment 3 Vladimir CLA 2006-08-27 22:17:51 EDT
After some thinking I realized that group parameter still in using to define running scope of the method. That means my previous suggestion will create much confusion in case it accepted. What if we introduce additional parameter to the "Total.sumRrunning" that will define if running sum must take into account hierarchy of groups.

Lets call related to group parameters "topGroup" and "bottomGroup" respectively.
If value of the "bottomGroup" is defined running sum will calculate value respective to group hierarchy defined by "topGroup" and "bottomGroup" parameters.

Suggested synopsis:
Total.first( expr [, filter [, topGroup [,bottomGroup] ]] )

If the birt team will accept the last suggestion I would able to solve the problem with the following expression:
Total.Sum(row["VisitCount"], null, 0, "InsuranceGroup")
Comment 4 Lin Zhu CLA 2006-08-28 02:52:22 EDT
Thank you for your insight this far to the problem. 

Actually the problem only happens to Running aggregations such as running sum (Though running aggregations are not initially designed to handle this sort of problem).This kind of aggregations has some usage that cannot be covered by BIRT's current aggregation framework. This bug is a case.

We will investigate this issue to see what we can do to such a usage.




Comment 5 Lin Zhu CLA 2007-04-09 09:42:15 EDT
*** Bug 173903 has been marked as a duplicate of this bug. ***
Comment 6 Lin Zhu CLA 2007-05-16 10:15:05 EDT
After discussion we defer this bug to post 2.2.0.
Comment 7 Wenfeng Li CLA 2009-05-27 20:41:46 EDT
add plan keyword to consider this enhancement for next release