How to create a formula in VS2005 Crystal Reports

Posted on 2007-10-16
Last Modified: 2013-11-26
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)...
Question by:SteveB2175
    LVL 100

    Accepted Solution

    Try this

    In the report header add a formula
    Name - DeclVars
    Global NumberVar PriceCat0;
    Global NumberVar PriceCat9;
    In the detail section
    Name - SetCatPrice
    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
    Global NumberVar PriceCat0;
    Global NumberVar PriceCat9;
    PriceCat0 - PriceCat9



    Author Comment

    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

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now