Crystal Reports: global variable running total not

2019-01-26 15:06发布

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.

6条回答
Luminary・发光体
2楼-- · 2019-01-26 15:37

Create a formula like this

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

and place it in group header section.

查看更多
贼婆χ
3楼-- · 2019-01-26 15:38

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.

查看更多
做自己的国王
4楼-- · 2019-01-26 15:39

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;
查看更多
Explosion°爆炸
5楼-- · 2019-01-26 15:44

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.

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-26 15:49

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)

查看更多
男人必须洒脱
7楼-- · 2019-01-26 15:51

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.

查看更多
登录 后发表回答