Staplerz
Staplerz

Reputation: 85

How to compare two data rows in one data set in BIRT

I'm new to BIRT and need an answer to the following question: How to compare two data rows in one data set in BIRT and then print it out to the document?

Upvotes: 1

Views: 1762

Answers (2)

hvb
hvb

Reputation: 2668

With an Oracle DB, you could easily achieve this with pure SQL using the "Analytic Function" LAG (see the Oracle documentation for details).

Independent from the DB, with BIRT, you could use a variable last_row:

Create some computed columns to keep the results of your comparisons. e.g. "FIRST_COLUMN_CHANGED" as boolean.

afterOpen event:

last_row = null;

onFetch event (pls note I'm not sure wether the actual data columns start at 0 or 1):

if (last_row != null) {
    if (last_row[0] == row[0]) {
        row["FIRST_COLUMN_CHANGED"] = false;
    } else {
        row["FIRST_COLUMN_CHANGED"] = true;
    }
} else {
    // do computations for the first record.
    row["FIRST_COLUMN_CHANGED"] = true;
}

// Copy the current row to last_row
last_row = {};
// modify depending on the number of columns
for (var i=0; i<10; i++) {
    last_row[i] = row[i];
}

Upvotes: 0

Rebecca Love
Rebecca Love

Reputation: 11

I am assuming you have a reason for not using a self-join query to bring in the data. One simple thing you could do is have 2 identical datasets and then create a new joint dataset using the 2.

Upvotes: 1

Related Questions