[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

How to create a formula in VS2005 Crystal Reports

I am running VS 2005 Crystal Reports.

I have an Sql Query that selects part number records from inventory.  Each part number as 2 distinct inventory categorys, "0" and "9".  Therefore I am returning 2 records for every part number

I have created a Crystal Report that displays everything that I want except for the difference between the 2 inventory category values. My report looks like this::

123           widget              

                   0             $15.24
                   9             $15.00
                                  $00.24      <==== This is the field I am trying to calculate

456          next description

                   0             $20.00
                   9             $21.00

The part number is in the "GroupHeaderSection1" area of the report.  The inventory category and price are in the details section of the report.

Thanks for any help you can offer.  (in case you haven't guessed, this is my first Crystal report)...
0
SteveB2175
Asked:
SteveB2175
1 Solution
 
mlmccCommented:
Try this

In the report header add a formula
Name - DeclVars
Formula
WhilePrintingRecords;
Global NumberVar PriceCat0;
Global NumberVar PriceCat9;
''
In the detail section
Name - SetCatPrice
Formula
WhilePrintingRecords;
Global NumberVar PriceCat0;
Global NumberVar PriceCat9;
If {CatField} = 0 then
    PriceCat0 := {PriceField};
else if {CatField} = 9 then
    PriceCat9 := {PriceField};
''

In the group footer
Name - DeclVars
Formula
WhilePrintingRecords;
Global NumberVar PriceCat0;
Global NumberVar PriceCat9;
PriceCat0 - PriceCat9

mlmcc



0
 
SteveB2175Author Commented:
Wow, it worked !!!

Thank you so very much, this would have taken me forever to figure out.

The only thing I changed was the last name in the group footer, I don't know if you intended for it to be the same name as the header formula or not.

Thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now