Jump to content
We've recently updated our Privacy Statement, available here ×

Show sum of a few consequtive records in front of the first one


sahandsafizadeh.s

Recommended Posts

I desire to show the following table in my report

 

   account       amount          sum

        1                  100              200

        1                   50                 -

        1                   50                 -

        2                   20                45

        2                   25                 -

 

As shown in the example above the sum column displays sum of amounts of a continuous series of records of same account. Like the first three records, their sum is 200 and it is displayed in the first row among them and the rest of the rows are left empty.

 

I'd appreciate any solutions

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images


I have created a simple sample report.

The key points are as follows.
* Calculate 'sum' by aggregating 'amount' using groups
* Set 'Group' for 'Evaluation Time' of 'sum
* Set '$V{Group1_COUNT}==1' as a display condition for 'sum' to display only the first line


- Preview image
w20220822_preview.png.62c3ba331500b1ff05983b412edb4570.png

- Layout design image
w20220822_design.png.1cb37ea054ea4f804071a8059c3b118e.png

- SQL
w20220822_sql.png.50422911cfc1cc2241e82e908454c81d.png
w20220822_sql_datapreviw.png.a9a4a436132f479696046835d7a7b0cf.png

- Variable [sum]
w20220822_sum_variable.png.120f070f7b17b8dce5ef6772e2d4f9b6.png

- Text field [sum]
w20220822_sum_text.png.14045e57c265a3bbdcb3b4004b1659b4.png
w20220822_sum_text_print.png.ef257b765b7c5e765b03a7b17e6b3649.png

Link to comment
Share on other sites

Here is how you can do it in SQL.

SELECT A.account     , A.amount     , case when a.rn = 1 then a.sum end as sumFROM (    select B.account         , B.amount         , sum(B.amount) over (PARTITION BY B.account) as sum         , ROW_NUMBER() OVER (PARTITION BY B.account order by b.account)  as rn    from (        select 1 as account, 100 as amount from dual        union all        select 1, 50 from dual        union all        select 1, 50 from dual        union all        select 2, 20 from dual        union all        select 2, 25 from dual    ) B) A[/code]
+-------+------+----+|ACCOUNT|AMOUNT|SUM |+-------+------+----+|1      |100   |200 ||1      |50    |    ||1      |50    |    ||2      |20    |45  ||2      |25    |    |+-------+------+----+[/code]

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...