Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Determine if data set row value is a number
Paul A
Hi again,
I am returning a Java Object from my ODA Driver into the BIRT Report for a number of columns. This will return either a number or a string.
This is displayed fine in my table on the report. However, I want to be able to aggregate on the column.
The data in the Temperature column looks like the following:
Missing
Missing
Error
6.5
7.2
8.5
I have dragged the Aggregation palette quick tool into the Footer Row of my table to do this. When I preview the report I get the following error in red text at the end of the report:
Data (id = 90):
+ A BIRT exception occurred. See next exception for more information.
Can not convert the value of Missing to Double type. (Element ID:90)
I need to be able to filter the column data to do this but I am not sure how. I would like to use something like the following filter condition:
new Number( row["Temperature"] ) != Number.NaN
The following works but I do not want to use it as there may be other strings in the column data that are not Missing or Error, such as Bad, etc:
BirtComp.notEqual(row["Temperature"], "Missing")
or
BirtComp.notEqual(row["Temperature"], "Missing") || BirtComp.notEqual(row["Temperature"], "Error")
Are there any ways to do this in a nice manor?
Thanks
Andez
Find more posts tagged with
Comments
mwilliams
In the example above, you could check each character of your number string if it's 0-9 or '.'. After looping through, if that's all you have, you'll know it's a number. All others would get filtered out. May not be the greatest solution, but I don't know any other way right off the top of my head.
paulk
The javascript function isFinite(<em class='bbc'>string</em>) will return false for a string and true for a numeric value.
thuston
In 2.6 there is a JavaScript Globals function isNaN()<br />
<br />
isNaN(row["OFFICECODE"])<br />
isNaN("string") ==> true<br />
inNaN("123") ==> false<br />
<br />
So you can make a computed column with expression:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>if ( isNaN(row["OFFICECODE"]) )
0;
else
parseFloat(row["OFFICECODE"]);</pre>
Paul A
Thanks thuston,
This was what I was looking for. I've added the check on my Aggregation Filter Condition as follows:
!isNaN( row["Temperature"] )
Andez