Skip to main content



      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 05:41 Go to next message
Eclipse UserFriend
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 05:31] by Moderator

Re: Computing between data from the same column [message #1068273 is a reply to message #1068122] Fri, 12 July 2013 17:29 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Computing between data from the same column [message #1072189 is a reply to message #1068273] Mon, 22 July 2013 05:01 Go to previous messageGo to next message
Eclipse UserFriend
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 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Try something like this:

if (vars["datavar"] == ""){
	vars["datavar"] = row["value"];
	null;
}
else{
	temp = vars["datavar"] - row["value"];
	vars["datavar"] = row["value"];
	temp;
}
Re: Computing between data from the same column [message #1072689 is a reply to message #1072402] Tue, 23 July 2013 05:30 Go to previous messageGo to next message
Eclipse UserFriend
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 17:04 Go to previous message
Eclipse UserFriend
Great! Glad to help! Smile
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: Mon Mar 24 10:24:06 EDT 2025

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

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

Back to the top