5

Using Crystal Reports I'm trying to display the running total of a database field in the header where all the labels are.

I've attempted to do this by placing the running total (RTversion) into a formula field with the following:

Shared stringvar CurrentVers; 
CurrentVers := {#CurrentVers}; 

and then in the page header section I have the following:

Shared stringvar CurrentVers; 
EvaluateAFter({#currentVers}); 
CurrentVers; 

with {#CurrentVers} running the 1st largest number.

Is this incorrect?

Update: The goal is to display the latest version in the header near the labels to show what the current verseion is for comparison.

Community
  • 1
  • 1
phill
  • 13,434
  • 38
  • 105
  • 141
  • 2
    My guess is you are trying to display a value before it's been set. – OMG Ponies Nov 02 '09 at 16:48
  • doesn't the EvaluateAfter() function tell it to wait until the running total #CurrentVers finishes? – phill Nov 02 '09 at 17:16
  • +1 Good Question. Although I know this is a common question, I wasn't able to find it here on SO so this will serve as a good reference for people. – Dusty Nov 04 '09 at 01:52

6 Answers6

4

Running-Total Fields, in my experience, only work in the footer sections.

You will need to create a manual running total.

Add a formula field to the Details section that populates a Global variable with whatever you are trying to capture. Something like:

//use WhileReadingRecords if the values can be gathered as the report pulls in values from the database.  Otherwise, use WhilePrintingRecords. 
WhileReadingRecords;
Global Stringvar CurrentVers;
//logic here to capture what you want
CurrentVers:=...

Add another formula field to the Header section. Add these two lines to it:

WhilePrintingRecords;
Global Stringvar CurrentVers;
craig
  • 25,664
  • 27
  • 119
  • 205
  • How do you do a manual running total to screen for the maximum value of the currentversion? Do you use Maximum() function in the details section? I tried that much and it gave me an error saying it can't evaluate with WhileReadingRecords(). – phill Nov 11 '09 at 18:47
  • I took out WhileReadingRecords, set the currentvers := ... and used the EvaluateAfter() function in the header and it worked. – phill Nov 11 '09 at 21:15
4

Create a formula like this

formula = Count ({Field to count},{GroupFieldName}) 

and place it in group header section.

Pops
  • 30,199
  • 37
  • 136
  • 151
1

I figured it out..

I had to add a subreport to the main report. I copied the main report and renamed it as a subreport. In the subreport, I added a shared variable and then passed it to the main report. The trick is to place the subreport in the same group header, but a separate section above the section that needs to be suppressed. I actually added the following sections:

New section (same group-I placed subreport here; do not suppress) New Section (same group - I placed shared variable value here; do not suppress) Original Section (same group that has a header I need suppressed based on a running total)

Sarah
  • 21
  • 1
  • 1
  • 4
0

You can solve this with just one formula field:

WhilePrintingRecords;
// Enter logic here e.g.
// maximum({mytable.myfield});

The WhilePrintingRecords; forces the formula to not be evaluated until all records have been read from the database, and therefore the formula field will display the correct result even if placed in a header.

LapplandsCohan
  • 706
  • 4
  • 13
  • 29
0

The key I found is that the formula field being passed needs to be placed on the subreport. I placed mine in the footer then suppressed it.

0

If {#CurrentVers} is a regular running total field, you should be able to place it in the page header directly rather than resort to an additional formula. I don't see the need for either formula field here, unless there's something unusual in the composition of {#CurrentVers} and a 'largest number' running total shouldn't require anything out of the ordinary.

MartW
  • 12,348
  • 3
  • 44
  • 68
  • Maybe I'm wrong on this, but I don't think just placing the running total in the header will work because of how the report reads top to bottom. This is off the top of my head so I could be wrong. – Dusty Nov 04 '09 at 01:37
  • They display, but obviously they only reflect the records processed up to that point. But the original question is far from clear on what they're trying to accomplish. – MartW Nov 04 '09 at 07:56