Crystal Reports: global variable running total not displaying in header

33,394

Solution 1

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;

Solution 2

Create a formula like this

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

and place it in group header section.

Solution 3

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)

Share:
33,394
phill
Author by

phill

Programming server admin stuff with vbscript, python, powershell, php, and c#.

Updated on April 23, 2020

Comments

  • phill
    phill almost 4 years

    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.

  • Arushi Rajput
    Arushi Rajput over 14 years
    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.
  • MartW
    MartW over 14 years
    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.
  • phill
    phill over 14 years
    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
    phill over 14 years
    I took out WhileReadingRecords, set the currentvers := ... and used the EvaluateAfter() function in the header and it worked.