Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » [SOLVED] Computing between data from the same column
[SOLVED] Computing between data from the same column [message #1068122] Fri, 12 July 2013 09:41 Go to next message
Paolo Aprile is currently offline Paolo AprileFriend
Messages: 24
Registered: June 2013
Junior Member
Hi!

I'm trying to calculate the difference between 2 numbers listed (consecutively) in the same column.

I have an XML data source and I'm using a computed column to calculate the difference between the value any item and that of the item that follows.

Ideally, given a "value" column, it should be something like:

BirtMath.subtract(row["value",n], row["value",n+1])

This would be very simple if the data where in separate columns but, as it happens, I don't know how to identify the 2 values in the Expression builder to complete the instruction. Is there a definite syntax for this?

Thanks for your attention!

[Updated on: Tue, 23 July 2013 09:31]

Report message to a moderator

Re: Computing between data from the same column [message #1068273 is a reply to message #1068122] Fri, 12 July 2013 21:29 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

One way would be to define a variable in your initialize script or you could probably use a report variable to "", 0, or null or something. Then, in your computed column, you could check the variable against the current row. After you do your calculation, you would set the value of the variable to the current row's value to check against the next row, then write out your computed value to the column. Hope this makes sense. Smile Let me know if you have questions.

Michael

Developer Evangelist, Silanis
Re: Computing between data from the same column [message #1072189 is a reply to message #1068273] Mon, 22 July 2013 09:01 Go to previous messageGo to next message
Paolo Aprile is currently offline Paolo AprileFriend
Messages: 24
Registered: June 2013
Junior Member
Hi Micheal! Thanks for your help!
Ok, I finally got around to try your suggestion, and used the following code to initialize my computed column:


if (vars["datavar"] = "")
{
	vars["datavar"] = row["value"];
	"";
}
else if (vars["datavar"] == row["value"])
{
	0;
}
else if (vars["datavar"] != row["value"])
{
	BirtMath.subtract(vars["datavar"], row["value"]);
	vars["datavar"] = row["value"];
}



When I run the report, i get "There are errors evaluating script". Can anyone point out where I went astray? O_o

Thanks for your time!

Paolo
Re: Computing between data from the same column [message #1072402 is a reply to message #1072189] Mon, 22 July 2013 17:24 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Try something like this:

if (vars["datavar"] == ""){
	vars["datavar"] = row["value"];
	null;
}
else{
	temp = vars["datavar"] - row["value"];
	vars["datavar"] = row["value"];
	temp;
}


Michael

Developer Evangelist, Silanis
Re: Computing between data from the same column [message #1072689 is a reply to message #1072402] Tue, 23 July 2013 09:30 Go to previous messageGo to next message
Paolo Aprile is currently offline Paolo AprileFriend
Messages: 24
Registered: June 2013
Junior Member
Ok, I customized a little your suggestion and now it works! =)

And not just with numerical data: I was even able to adapt it to calculate the time difference between 2 timestamp in a crosstab!
Thanks for your time and for your help!

Paolo
Re: Computing between data from the same column [message #1072962 is a reply to message #1072689] Tue, 23 July 2013 21:04 Go to previous message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

Great! Glad to help! Smile

Michael

Developer Evangelist, Silanis
Previous Topic:PDF export of report with grid doesn't work correctly if cell is broken across two pages
Next Topic:Issues with Report in Maximo 7.5
Goto Forum:
  


Current Time: Fri Apr 19 13:29:27 GMT 2024

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

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

Back to the top