Create a conditional summary using Crystal Reports

Posted on 2008-11-18
Last Modified: 2012-05-05
i have a dataset with a field called TYPE.   The data contains 3 different types, "A", "B" and "C".
I would like to use Crystal Reports to count how many records are of type "A", how many of type "B" and how many of type "C".   The field is a string so simply TYPE = "C" will tell me if it is type "C".
Crystal Reports has a Set of Summary functions available in the Formula Editor.   One of the functions is Count() which counts the number of records.   The parameters are
       Count(fld),   Count(fld,condFld) or Count(fld,condFld,value).

Is there any way to do this.   I tried making a new formula field called TYPEAT such that
     if TYPE="A" then
         formula = true
    end if

then I tried a second formula field typeac
Thinking that TYPEAT IS NOW A CONDITIONAL FIELD.   The formula editor will not accept this.

I can use parameter fields and perform the calculations in the main program, but i would like to use a conditional count formula.    

Can this be done with Crystal Reports????
Question by:knk53
    LVL 100

    Accepted Solution

    I assume you are selecting the fields when you build the summary.

    Have you tried right clicking the field
    Click INSERT --> SUMMARY
    Can you insert a summary?

    To summarize on a condition field it needs to be a group in the report.

    Another way to do this would be

         if TYPE="A" then
             formula = 1
        end if

    You can then insert a summary as a sum to get the count.

    LVL 2

    Author Comment

    Thanks for responding
      I was already able to use a formula such as you suggested and return 1 or 0, then make another field that would SUM the first field.  However, that means I need to make 2 fields for each conditional count I want in my report.   The first field would return 1 or 0 based on the the condition.  The second field would sum the first field.  
    Is there any way to create this as a single field, as opposed to 2 separate fields.
    LVL 100

    Expert Comment

    Unless you are grouping by the formula you tried, no.

    LVL 34

    Assisted Solution

    I'm not sure what you mean by "create this as a single field".  If you're trying to have one "field" produce a count for each TYPE, then, like mlmcc, I don't see any way to do it unless you're grouping on the TYPE, in which case you could show a count for each TYPE in the group footer.

     FWIW, in addition to mlmcc's suggesting of using formulas to produce a count of each TYPE, another option is to use running totals.  Running totals allow you to specify conditions, like only increment when TYPE is a certain value.  So, you'd have one running total for each value in TYPE.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now