Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Calculates with 2 Data Sets(How can calculate a expression from 2 data set?)
Calculates with 2 Data Sets [message #902553] Sat, 18 August 2012 11:27 Go to next message
JOSE LUIS is currently offline JOSE LUISFriend
Messages: 5
Registered: August 2012
Junior Member
Hi,

I have a question.

I have two databases one is access and other is MySql. I use information in tables and grid for each of these tables and using differents datasets, but when i want to create a DATA Cell with a result from 2 datasets from i have a problem, I don't know what can i do?.

My case is:

DataSet1 = Only it has a row with a number. TOTALSALES = 1112
DataSet2 = Only it has a row with a numbre. TOTALCOST = 345

I want show the value --> TOTALSALES - TOTALCOST in a grid, but i don't know if this is possible or impossible. The DATA CELL i would like to name = BENEFITS

BENEFITS = DataSet1.TOTALSALES - DataSet2.TOTALCOST
BENEFITS = 1112 - 345 = 767

Thanks.

(sorry for my english its no good)

[Updated on: Sun, 19 August 2012 12:48]

Report message to a moderator

Re: Calculates with 2 Data Sets [message #902861 is a reply to message #902553] Mon, 20 August 2012 18:32 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You could do something like:
data set one table
in a table with ds 1 you could write a onCreate script for the data
filed that displays total sales.

reportContext.setGlobalVariable("TS", this.getValue());
or
reportContext.setGlobalVariable("TS",
this.getRowData().getColumnValue("TOTALSALES"));


do the same for the data set 2 total cost, but use a different variable
name, say TC.

Then below both tables add a data item (No binding needed) with the
expression:

reportContext.getGlobalVariable("TS")/reportContext.getGlobalVariable("TC");

You may want to get TC first and check for a 0 value.

Jason

On 8/18/2012 7:27 AM, JOSE LUIS wrote:
> Hi,
>
> I have a question.
>
> I have two databases one is access and other is MySql. I use information
> in tables and grid for each of these tables and using differents
> datasets, but when i want to create a DATA Cell with a result from 2
> datasets from i have a problem, I don't know what can i do?.
>
> My case is:
>
> DataSet1 = Only it has a row with a number. TOTALSALES = 1112
> DataSet2 = Only it has a row with a numbre. TOTALCOST = 345
>
> I want show the value --> TOTALSALES - TOTALCOST in a grid, but i don't
> know if this is possible or impossible. The DATA CELL i would like to
> name = BENEFITS
>
> BENEFITS = DataSet1.TOTALSALES - DataSet1.TOTALCOST BENEFITS = 1112 -
> 345 = 767
>
> Thanks.
> (sorry for my english its no good)
Re: Calculates with 2 Data Sets [message #904139 is a reply to message #902861] Mon, 27 August 2012 21:21 Go to previous messageGo to next message
JOSE LUIS is currently offline JOSE LUISFriend
Messages: 5
Registered: August 2012
Junior Member
Thanks Jason, this is information what i needed. Kind Regards
Re: Calculates with 2 Data Sets [message #905164 is a reply to message #902861] Wed, 29 August 2012 20:42 Go to previous messageGo to next message
JOSE LUIS is currently offline JOSE LUISFriend
Messages: 5
Registered: August 2012
Junior Member
Hello Again,

I have a problem. When data are INTEGER i have no problem, but when data are DECIMAL or MONEY, RESULT is 0 in all case.

Do you know what is it happening?

Kind Regards
Re: Calculates with 2 Data Sets [message #905588 is a reply to message #905164] Thu, 30 August 2012 17:34 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You can try two things. First instead of using the setGlobalVariable
just put an a script in like:

TS=this.getRowData().getColumnValue("TOTALSALES");

Note that there is no var keyword which should make TS available
downstream. So in an expression later you could just use TS/TC;

or
Specify the type to store the variable
importPackage(Packages.java.lang);
var mydbl = new Double(this.getRowData().getColumnValue("TOTALSALES"));
reportContext.setGlobalVariable("TS", mydbl);

Jason

On 8/29/2012 4:42 PM, JOSE LUIS wrote:
> Hello Again,
>
> I have a problem. When data are INTEGER i have no problem, but when data
> are DECIMAL or MONEY, RESULT is 0 in all case.
>
> Do you know what is it happening?
>
> Kind Regards
Re: Calculates with 2 Data Sets [message #906195 is a reply to message #905588] Fri, 31 August 2012 20:34 Go to previous messageGo to next message
JOSE LUIS is currently offline JOSE LUISFriend
Messages: 5
Registered: August 2012
Junior Member
Thanks for your information, but if I use the first expression

reportContext.setGlobalVariable("TS", this.getValue());

for example --> TS = 4.945,45 and TC = 2800,00

if I apply to get result:

reportContext.getGlobalVariable("TS")/reportContext.getGlobalVariable("TC");


the result is: 4945452800. This expression dosen't sum, this expression joining the numbers like a text. Do you know, what is happening?.

Thanks.
Re: Calculates with 2 Data Sets [message #906215 is a reply to message #906195] Fri, 31 August 2012 21:16 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

can you try?

parseFloat(reportContext.getGlobalVariable("TS"))/parseFloat(reportContext.getGlobalVariable("TC"));

Jason

On 8/31/2012 4:34 PM, JOSE LUIS wrote:
> Thanks for your information, but if I use the first expression
> reportContext.setGlobalVariable("TS", this.getValue());
>
> for example --> TS = 4.945,45 and TC = 2800,00
> if I apply to get result:
>
> reportContext.getGlobalVariable("TS")/reportContext.getGlobalVariable("TC");
>
>
>
> the result is: 4945452800. This expression dosen't sum, this expression
> joining the numbers like a text. Do you know, what is happening?.
>
> Thanks.
Re: Calculates with 2 Data Sets [message #906380 is a reply to message #906215] Sat, 01 September 2012 09:34 Go to previous messageGo to next message
JOSE LUIS is currently offline JOSE LUISFriend
Messages: 5
Registered: August 2012
Junior Member
Good Morning Jason,

When I used this expression

parseFloat(reportContext.getGlobalVariable("TS"))-parseFloat(reportContext.getGlobalVariable("TC"));

Eclipse give me a error:

Grid (id = 2825):
+ Can not convert the value of NaN to BigDecimal type.
CONVERT_FAILS ( 1 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: Can not convert the value of NaN to BigDecimal type.

Do you know what can we do?

Thanks, Kindest regards
Re: Calculates with 2 Data Sets [message #908003 is a reply to message #906380] Tue, 04 September 2012 14:33 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Verify that reportContext.getGlobalVariable("TS") or
reportContext.getGlobalVariable("TC") is not null before you do the
division.

Jason

On 9/1/2012 5:34 AM, JOSE LUIS wrote:
> Good Morning Jason,
>
> When I used this expression
> parseFloat(reportContext.getGlobalVariable("TS"))-parseFloat(reportContext.getGlobalVariable("TC"));
>
>
> Eclipse give me a error:
>
> Grid (id = 2825): + Can not convert the value of NaN to BigDecimal type.
> CONVERT_FAILS ( 1 time(s) )
> detail : org.eclipse.birt.report.engine.api.EngineException: Can not
> convert the value of NaN to BigDecimal type.
>
> Do you know what can we do?
>
> Thanks, Kindest regards
Previous Topic:problem in binding data source to a table from BIRT library
Next Topic:apache.commons.io dependency problem
Goto Forum:
  


Current Time: Wed Apr 24 17:39:02 GMT 2024

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

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

Back to the top