Print Page | Close Window

Subtotal from a Running Total

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22723
Printed Date: 27 Apr 2024 at 10:54pm


Topic: Subtotal from a Running Total
Posted By: jsh8286
Subject: Subtotal from a Running Total
Date Posted: 29 Jan 2019 at 2:10pm
Have a report that does not have any groupings. Only a detail section. I am trying to use a running total to calculate a subtotal all within the detail section.The reason is we need multiple subtotals but all within the detail section of the report.

So here is an example of the items listed on the report:

Item A               100.00
Item B               100.00
Item C               100.00
SUBTOTAL             300.00

Item D               200.00
Item E               100.00
SUBTOTAL             300.00

We want the running total to add the items and put the running total amount where you see above. We have done this but we also need to reset the running total when it encounters a SUBTOTAL.

So in the example above if I were to put our running total beside the amounts also with the knowledge the running total needs to be reset when it encounters a subtotal here is what we get:

Item A               100.00        100.00
Item B               100.00        200.00
Item C               100.00        300.00
SUBTOTAL               0.00

Item D               200.00        200.00
Item E               100.00        300.00
SUBTOTAL               0.00     

So as you can see the SUBTOTAL is at 0.00 since we need to reset it. All we need is for the last running total from the line above to pass down to the subtotal line and we are good.

Any suggestions or postings would be greatly appreciated.



Replies:
Posted By: kevlray
Date Posted: 30 Jan 2019 at 4:58am
I have never tried sub-totaling without a group of some sorts.  There maybe a way to do it with a manual running total.  I would have to think about this awhile to see if I could come up with a solution.


Posted By: kevlray
Date Posted: 30 Jan 2019 at 5:21am
First create a formula something like this.

shared numbervar subtotal;
if {Sheet1_.Item } = 'SUBTOTAL' THEN
    subtotal
    else if previous({Sheet1_.Item })  = 'SUBTOTAL' then
        subtotal := {Sheet1_.amount}
    else    subtotal := subtotal +{Sheet1_.amount};

then create a second detail line that will have the item column and formula column in it.  The first detail row will be suppressed if the item is equal to SUBTOTAL, the second detail row will be suppressed if the item is not equal to SUBTOTAL.


Posted By: DBlank
Date Posted: 30 Jan 2019 at 8:18am
I would also suggest that you already had to create logic to decide when to 'insert' the subtotal which I assume is on a details B section.
That same logic can be applied to the RT for when to reset (using a formula).



Print Page | Close Window