Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Global Variables with Sub Reports - Get Totals
Krelek1000
Hi All,
I was hoping someone can help me with this issue that I am having with BIRT. I am on BIRT V2.1.2 and I created a report with a subreport.
Now the issue that I have is that I need to total several integers in the sub report together, which I was able to do in the sub report's table using the:
Total.sum(row["value"])
But part of the issue that I am having is that the report requestor wants a Total Sum on the main report.
I looked at several posts for global variables. My thought is to use a global variable and have it some up the numbers in the sub report and then put that total sum into the main report by referencing the global variable on the footer...
Problem is that the global variable is returning 0 on the footer.
I do not know how a report is rendered completely. I have looked at posts that reference the "scripting" part of the report when done but I do not know if there is one that shows when a sub report is used.
I intialize the variables in the Intiallize script but I do not know when the rendering of the variable is done on the footer...
Is there anywhere else I need to declare or reference the variable in order to make it be seen on the Footer?
Currently it is only in the Intialize script and the Fetch script of the sub data set (value= value + row["value"]).
TIA,
Krelek
Find more posts tagged with
Comments
mwilliams
Hi Krelek,
You'll need to sum the values in the onCreate script of the data element that you're displaying the sub table total in. If you attach your report, I can help you set it up correctly.
Krelek1000
Hey Michael,
I am posting it but I do not know if it will completely run for you. It is a report built from a template for an IBM product...
mwilliams
Krelek,
I'll just modify it for you to see if it works. I won't be able to run it without access to your data. Can you tell me what data items you're wanting to total and where you'd like to display them? Thanks.
Krelek1000
Thanks Michael,
The data items I am trying to total on the sheet are located in the SubDataSet.
They are reghrs and othrs.
The global variables are TotalREGHRS and TotalOTHRS in the intialize statement.
I like to render them in the Footer Row of the main report.
There might be a Data Label in on of them just called DATA1 (predraft
).
Thanks very much!
Krelek
mwilliams
Krelek,
GRPRegHrs2 and GRPOTHrs2 work correctly, so summing those values would work too, correct?
Krelek1000
Correct Michael.
reghrs is a sum on the SQL side
othrs is also a sum on the sql side
subReghrs sums reghrs for the Craft group
subOTHrs sums othrs for the Craft group
GRPRegHrs2 sums reghrs for the entire Work Order (sub report table) (1 wo record)
GRPOTHrs2 sums othrs for the entire Work Order (sub report table) (1 wo record)
I need 2 more that does the same but for all Work Order records. So a sum of the GRP data fields would work sir...
Thanks
Ben
Krelek1000
Hey Michael,
I was wondering if you can point me in the direction of what to do for the OnCreate function... Should I include this function on each cell or data field?
TotalReg = TotalReg + Total.sum("reghrs")
Once that is done, how do I call the data field in the footer... Just reference the variable or do I need to put a function in the oncreate there also?
Thanks
Ben
mwilliams
Ben,
Try this report design. Since I can't run it, I can't test to make sure it works correctly. If a standard variable like this doesn't work, we may have to use persistentGlobalVariables. Let me know.
Krelek1000
Hey Michael,
I downloaded the fix that you sent me. It worked for a single record for the database but when you searched for multiple ones, BIRT didn't handle them right.
However, with a little bit of searching, I was able to find the answer...
Apparently BIRT 2.1.2 was looking or converting each of the global variables to a String. So when the OnCreate was ran it was adding the this.getValue() as a string to the global variable.
However, I was able to force them to numbers by adding the Number() to both the variable and to the this.getValue().
Here is the result of the onCreate (for Total.sum() footer on a sub report):
TotalREGHRS = Number(TotalREGHRS) + Number(this.getValue());
On the Expression fields you added to the Main Report table, modified them to this:
parseFloat(TotalREGHRS).toFixed(2);
This was to ensure that I get the 2 decimal places and the number.
All the numbers add up now... So in BIRT V2.1.2, steps are:
Declare Variables in the Intialize script:
TotalREGHRS = 0;
In the Data Type field of a Subreport (one that carries Total.sum(row["field"]) in the onCreate:
TotalREGHRS = Number(TotalREGHRS) + Number(this.getValue());
In the Footer, add the expression:
parseFloat(TotalREGHRS).toFixed(2);
Thanks for the help! You sent me on the right path!
Ben
mwilliams
Ben,
Great to hear! I'm always glad to help! Thanks for the update on the exact solution needed for 2.1.2!