Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Expression Builder Scripting in BIRT 4.5
Istabrak
<p>Greeting to all,</p>
<p>I am using BIRT 4.5 bundled with Eclipse.</p>
<p>One of the data sets I am working on is a csv file with 500 or so columns.</p>
<p>Data fields in these columns are mostly numerical.</p>
<p>I have a requirement to add a number of computed columns.</p>
<p>The field values of these columns will be the sum of some of the fields of original 500 columns on the same row.</p>
<p>I tried using the Expression Builder but that takes a long time to do and error prone.</p>
<p>Is there a way to write a script or other APIs where these computed columns fields expressions can be defined? For example:</p>
<p>- ComputedCol-1 = Sum (col1 to col 20).</p>
<p>- ComputedCol-2 = Sum (col21, col27, col30).</p>
<p> </p>
<p>And so on.</p>
<p> </p>
<p>Thx and BR</p>
Find more posts tagged with
Comments
pricher
<p>Hi,</p>
<p> </p>
<p>Assuming that you read in your CSV file and you let BIRT name the columns automatically (e.g. COLUMN_1, COLUMN_2, etc) you can add Computed Columns in the Data Set and use one of the following scripts:</p>
<p> </p>
<p>1. For adding columns that are in a range (e.g. columns 1 to 5):</p>
<pre class="_prettyXprint _lang-js">
var tot = 0;
var startCol = 1;
var endCol = 5;
for (idx = startCol; idx <= endCol; idx++) {
tot += row["COLUMN_" + idx]
}
</pre>
<p>2. For adding discrete columns (e.g. Column 1, column 2, columns 5):</p>
<pre class="_prettyXprint _lang-js">
var tot = 0;
var cols = [1,2,5];
for (idx = 0; idx < cols.length; idx++) {
tot += row["COLUMN_" + cols[idx]]
}
</pre>
<p>I have attached a sample report and data file.</p>
<p> </p>
<p>Hope this helps,</p>
<p> </p>
<p>P.</p>