Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » store values ​​in a Data Set to another
store values ​​in a Data Set to another [message #671921] Thu, 19 May 2011 11:19 Go to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
Hello,

Following the instructions from Jason in a previous post, I am conducting a series of tests to store values ​​in a Data Set to another. I am having a problem to calculate the following ratio. I give you an example:

1. Data Set1: This dataset includes an aggregation (count) of Several items on a aggregate group (by product). Example:
product1 - 3
product2 - 2
product3 - 1

2. Data Set2: This Data Set should make another similar to the previous aggregation grouped by product. Example:
product1 - 3
product2 - 2
product3 - 2

3. My goal is to calculate the "Data Set2" the following percentages grouped also by product:

product1: 3 / 3 = 100%
product2: 2 / 2 = 100%
product3: 1 / 2 = 50%

For this, I tried to store the variables of "Data Set1" by scripting as follows:

<method name="onCreate"> <! [CDATA [reportContext.setGlobalVariable (total1 "this.getValue ());]]></ method>
name="resultSetColumn"> <property total_DataSet1 </ property>


Then I inserted a "Data" with the following expression that seeks to calculate the percentage above mentioned:

(reportContext.getGlobalVariable ("total1) / row [" total_DataSet2 "]) * 100

Instead, the Report gives the following result:

product1: 1 / 3 = 33.33%
product2: 1 / 2 = 50%
product3: 1 / 2 = 50%

From which it follows that BiRT is only storing just one variable (the third result or "Data Set1: 1).

Can you tell me how I can store these 3 variables in the example in the "Data Set2? Where is the problem? Does aggregation introduced in the "Data Set 2 " or scripting?

Thanks
(no subject) [message #671991 is a reply to message #671921] Thu, 19 May 2011 14:17 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

instead of storing the value name as total1 use the current row product
as the name like:
reportContext.setGlobalVariable( row["product"], this.getValue());
This assumes that the aggregate is created once for each product. Then
just retrieve it the same way.

reportContext.getGlobalVariable( row["product"] );

Jason

On 5/19/2011 7:19 AM, gin1975 wrote:
> Hello,
>
> Following the instructions from Jason in a previous post, I am
> conducting a series of tests to store values ​​in a Data Set to another.
> I am having a problem to calculate the following ratio. I give you an
> example:
>
> 1. Data Set1: This dataset includes an aggregation (count) of Several
> items on a aggregate group (by product). Example:
> product1 - 3
> product2 - 2
> product3 - 1
>
> 2. Data Set2: This Data Set should make another similar to the previous
> aggregation grouped by product. Example:
> product1 - 3
> product2 - 2
> product3 - 2
>
> 3. My goal is to calculate the "Data Set2" the following percentages
> grouped also by product:
>
> product1: 3 / 3 = 100%
> product2: 2 / 2 = 100%
> product3: 1 / 2 = 50%
>
> For this, I tried to store the variables of "Data Set1" by scripting as
> follows:
>
> <method name="onCreate"> <! [CDATA [reportContext.setGlobalVariable
> (total1 "this.getValue ());]]></ method>
> name="resultSetColumn"> <property total_DataSet1 </ property>
>
>
> Then I inserted a "Data" with the following expression that seeks to
> calculate the percentage above mentioned:
>
> (reportContext.getGlobalVariable ("total1) / row [" total_DataSet2 "]) *
> 100
>
> Instead, the Report gives the following result:
>
> product1: 1 / 3 = 33.33%
> product2: 1 / 2 = 50%
> product3: 1 / 2 = 50%
>
> From which it follows that BiRT is only storing just one variable (the
> third result or "Data Set1: 1).
>
> Can you tell me how I can store these 3 variables in the example in the
> "Data Set2? Where is the problem? Does aggregation introduced in the
> "Data Set 2 " or scripting?
>
> Thanks
Re: (no subject) [message #672022 is a reply to message #671991] Thu, 19 May 2011 15:33 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
ok it works. Thanks!
(no subject) [message #672029 is a reply to message #671991] Thu, 19 May 2011 15:33 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
ok it works. Thanks!
Re: (no subject) [message #674039 is a reply to message #672029] Wed, 25 May 2011 16:13 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
I found a problem in passing parameters in the following type of report:

When I send this parameter to the aggregation:

reportContext.setGlobalVariable variable (row ["product"], this.getValue ()),

in those cases where it is null, the percentage instead of being zero, is 100. Is there any way to resolve this?

Thanks
Re: (no subject) [message #674040 is a reply to message #674039] Wed, 25 May 2011 16:15 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
I copy the expression of aggregation in question:
(reportContext.getGlobalVariable (row["products"])/row["total_items"])*100
Re: (no subject) [message #674069 is a reply to message #674040] Wed, 25 May 2011 17:44 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
What I have seen the results of the percentages, is that if the total reportContext.getGlobalVariable (row ["product"]) is null, when calculating the percentage, it defaults to the value 1. Examples:
- If the total is 2 and the global variable is null, the percentage is 200
- If the total is 1 and the global variable is null, the percentage is 100.
Re: (no subject) [message #674078 is a reply to message #674039] Wed, 25 May 2011 18:12 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Cant you just check the value for null first?

if( this.getValue() != null ){

}else{

}

Jason

On 5/25/2011 12:13 PM, gin1975 wrote:
> I found a problem in passing parameters in the following type of report:
>
> When I send this parameter to the aggregation:
>
> reportContext.setGlobalVariable variable (row ["product"], this.getValue
> ()),
>
> in those cases where it is null, the percentage instead of being zero,
> is 100. Is there any way to resolve this?
>
> Thanks
Re: (no subject) [message #674228 is a reply to message #674078] Thu, 26 May 2011 08:22 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member

Hello,

Still not working. I explain with a simple example:

- I create total1 aggregation, which counts the items associated with a list of products
- Added the following line in the XML:
<method name="onCreate"> <! [CDATA [reportContext.setGlobalVariable (row ["products_name"], this.getValue ());]]></ method>
name="resultSetColumn"> <property total1 </ property>

- I create next Agregation_total2, which counts another set of items associated with a product list.
- I create Data Item "Percentaje", which must calculate the percentage between total1 and Total2.

The problem arises when the number of products recorded in total1 is not equal to those recorded in Total2. I explain with an example:

total1 product1 = 1
total1 product2 = 2

Total2 product1 = 1
Total2 product2 = 2
Total2 product3 = 2

Percentage product1 = 1 / 1 = 100% OK
Percentage product2 = 2 / 2 = 100% OK
Percentage product3 = 1 / 2 = 100% NOK. This percentage should not appear as the product total1 3 is null.

I tried to include the following word in the data associated with percentage but does not work:
if (this.getValue ()! = null) {
(reportContext.getGlobalVariable (row ["products_name"]) / row ["Total2"]) * 100}


Can you tell me how I could try to fix this?
Thanks.
Re: (no subject) [message #674349 is a reply to message #674228] Thu, 26 May 2011 15:14 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Do you have a space between ! and = ?

For testing purposes add to the script like:

importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "c:/templ/mycalcs.txt", true ) );
out.println( "row value "+ reportContext.getGlobalVariable(
row["products_name"]));
out.close();

check the mycalcs.txt to see if the value is showing null. If it is
use

var top=0;
if( reportContext.getGlobalVariable( row["products_name"]) != null ){
top = reportContext.getGlobalVariable( row["products_name"]);
}
then use top in your calculation.

Jason


On 5/26/2011 4:22 AM, gin1975 wrote:
>
> Hello,
>
> Still not working. I explain with a simple example:
>
> - I create total1 aggregation, which counts the items associated with a
> list of products
> - Added the following line in the XML:
> <method name="onCreate"> <! [CDATA [reportContext.setGlobalVariable (row
> ["products_name"], this.getValue ());]]></ method>
> name="resultSetColumn"> <property total1 </ property>
>
> - I create next Agregation_total2, which counts another set of items
> associated with a product list.
> - I create Data Item "Percentaje", which must calculate the percentage
> between total1 and Total2.
>
> The problem arises when the number of products recorded in total1 is not
> equal to those recorded in Total2. I explain with an example:
>
> total1 product1 = 1
> total1 product2 = 2
>
> Total2 product1 = 1
> Total2 product2 = 2
> Total2 product3 = 2
>
> Percentage product1 = 1 / 1 = 100% OK
> Percentage product2 = 2 / 2 = 100% OK
> Percentage product3 = 1 / 2 = 100% NOK. This percentage should not
> appear as the product total1 3 is null.
>
> I tried to include the following word in the data associated with
> percentage but does not work:
> if (this.getValue ()! = null) {
> (reportContext.getGlobalVariable (row ["products_name"]) / row
> ["Total2"]) * 100}
>
>
> Can you tell me how I could try to fix this?
> Thanks.
Re: (no subject) [message #674370 is a reply to message #674349] Thu, 26 May 2011 16:42 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
Mycalcs result file after making a test:

row value 1
row value 1
value row 2
value row 2
row value 1
row value 1

This means that is repeated by calculating the total number of existing projects in total_2.

product1_total1 = 1
product2_total1 = 2

product1_total2 = 2
product2_total2 = 3
product3_total2 = 2

percentage1 = 1 / 2 = 50%
percentage2 = 2 / 3 = 66%
percentage2 = 1 / 2 = 50%

How can we fix this?

Thanks
Re: (no subject) [message #674375 is a reply to message #674370] Thu, 26 May 2011 17:00 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

I am confused on where you have the scripts.
Is this a report I can run? If so can you post it?

Jason

On 5/26/2011 12:42 PM, gin1975 wrote:
> Mycalcs result file after making a test:
>
> row value 1
> row value 1
> value row 2
> value row 2
> row value 1
> row value 1
>
> This means that is repeated by calculating the total number of existing
> projects in total_2.
>
> product1_total1 = 1
> product2_total1 = 2
>
> product1_total2 = 2
> product2_total2 = 3
> product3_total2 = 2
>
> percentage1 = 1 / 2 = 50%
> percentage2 = 2 / 3 = 66%
> percentage2 = 1 / 2 = 50%
>
> How can we fix this?
>
> Thanks
Re: (no subject) [message #674380 is a reply to message #674375] Thu, 26 May 2011 17:15 Go to previous messageGo to next message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
You could not run the report from your computer. Can i send you any part or information in particular (scripts, querys, expresions, etc.)?
Re: (no subject) [message #674560 is a reply to message #674380] Fri, 27 May 2011 11:10 Go to previous message
gin1975  is currently offline gin1975 Friend
Messages: 30
Registered: April 2011
Member
Ok is solved
Thanks
Previous Topic:PDF no wrapping in BIRT Report Designer 2.5.1
Next Topic:More than one category in x-axis
Goto Forum:
  


Current Time: Thu Apr 18 23:07:34 GMT 2024

Powered by FUDForum. Page generated in 0.02706 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top