Question

So Iam making a birt report on enclipse my goal is to output on each page amount of sales of a given person, not overall amount of sales of that person.

Consider this table(consider we only have 1 person):

    personID   sales   date
    -------    -----  -----
    111        10     2010-02-02
    111        15     2010-02-03
    111        5      2010-03-03
    111        7      2010-04-03
    111        8      2011-01-01
    111        9      2013-01-01
    111        20     2014-01-01
    111        25     2014-03-02

The scenario on each page:

  • It shows 3 results(which I want)
  • but below each page its showing 99 sales (which I don't want)

What I want is that:

  • on 1st page it shows 30 sales (for 3 rows)

  • on 2nd page it shows 24 sales(for 3 rows)

  • and last page it shows 45(for 2 remaining rows)

what I did is that (i dont know if its right approach):

    DENSE_RANK() OVER (ORDER BY sales) AS Row,
convert(integer,ROW_NUMBER() over(order by sales)/4) as page

which turned my table into

     personID   sales   date      Row     page
    -------    -----  -----       ----    ----
    111        10     2010-02-02   1       0
    111        15     2010-02-03   2       0
    111        5      2010-03-03   3       0
    111        7      2010-04-03   4       1
    111        8      2011-01-01   5       1
    111        9      2013-01-01   6       1
    111        20     2014-01-01   7       1
    111        25     2014-03-02   8       2

As you can see there's another issue which is:

  • the 1st 3 rows got page(0)

  • but row 4-5-6-7 got page 1 which is wrong it should have been row 4-5-6 page 1

  • and row 7-8 page 2

I am also working on eclipse using JavaScript

       <method name="onPageEnd"><![CDATA[var sales = this.getInstancesByElementName("sales");
    var tmp=0;

    if( sales != null )
    {
     for(var i=0; i< sales.length; i++ )
     {
    for(var j=0;j<3;j++)
    {
        //Instance of DataItemInstance
        var sales = sales[i];
        tmp+=parseInt(sales.getValue());
    }
     }

     }
Was it helpful?

Solution

Once your query results are correct, you should compute SUM(sales) based on the page. This can be done either with SQL (Oracle SQL syntax)

with x as
(
  your_query_here
)
select x.*,
       sum(sales) over (partition by page) -- IIRC
from x

or with BIRT, if you create a GROUP (called "page" for example) in your (layout) table, and an aggregate column binding based on this group.

Now to the query itself: I don't think that the DB actually shows the results you state with your query. Probably "Row" is defined in your query as

DENSE_RANK() OVER (ORDER BY "date" AS "Row"

I often use something like this for "matrix reports in SQL" and the like (asssuming you want 3 rows/page). This is a puire SQL solution:

with 
y as (
    select ...,
    ROW_NUMBER() over(order by "sales") partition by ("personID") - 1 as "Row" 
    -- Note: Row is zero-based: 0,1,2,...
),
x as (
    select y.*,
           MOD(y."Row", 3)  + 1  as "RowOnPage"
           trunc(y."Row"/3) + 1  as "Page"
    from y
)
select x.*,
       sum("sales") over (partition by "personId", "Page") as SumSalesPerPersonAndPage
       -- IIRC
from x

This is probably not quite correct (because I don't know how you intend to handle the different persons), but you get the idea...

For creating reports, it is a great advantage to know analytic functions.

I usually test my queries outside of BIRT (eg with SQL*Developer).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top