Crystal Reports – Using Shared Variable in version 8.5

This example show how to use Shared Variables in CR 8.5

I know it is an old version but the principles can be used in later versions as well.

Objective was to transfer a value from a sub-report into the main report for further calculations.

1. First create the sub-report, and link it to the Main report using the Insert Menu


2. When the link has been setup, insert a new Formula Field


In the new formula field you add a Shared Variable.

Shared NumberVar myTotal :=Sum ({Your.Field})

3. Next you go the Main Report and add as well a new Formula field.


In the new formula field you add reference to the previous  Shared Variable, of the sub-report.

Shared NumberVar myTotal;

4. Add the new Formula field in the main report


Keep in mind that you need to add the field in a SECTION BELOW the detailed section of the main report. In order for the variable to grab the values correct.

5. Making calculations using Shared Variables.

You can use the this just like any other field value to make your calculations.

Shared NumberVar myTotal;
If {Your.Field} <> 0 then
myTotal / {Your.Field};


To get the sub-report field properly formatted in your report it’s a bit tricky.

Remove the BORDERS and if needed uncheck the Keep Objects Together




Enjoy !!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: