|
(no subject) [message #671991 is a reply to message #671921] |
Thu, 19 May 2011 14:17 |
|
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 #674078 is a reply to message #674039] |
Wed, 25 May 2011 18:12 |
|
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 #674349 is a reply to message #674228] |
Thu, 26 May 2011 15:14 |
|
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 #674375 is a reply to message #674370] |
Thu, 26 May 2011 17:00 |
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02706 seconds