Crystal - Count if with multiple qualifiers

Posted on 2008-11-07
Last Modified: 2012-05-05
I want to count Column A if Columns B and C meet a certain criteria:

Col A     Col  B    Col C
1            True     Original
2            True     Original
3            null       Original
4            True     Canceled

The result I am looking for would be a sum of 2 from the above data.

I think the formula I came up with is close but I keep getting a "The Keyword 'Then' is missing" Here is what I came up:

if ({tblCases.IsComplete} = true) and
if ({tblCases.CaseStatus} = 'original')) then Count ({tblCases.NumberCases})
Question by:dsabine
    LVL 77

    Expert Comment

    We need to be quite clear about what you want here.

    Count() counts 1 for each item, irrespective of the item's value.
    If you want to add up the values then you need Sum not Count.

    But it looks like you should be using a Running Totals field for this whichever you want.

    Seelect the field to summatrise as ColA.
    Select Sum or Count whichever it is you want.
    In the 'Evaluate when' you select Use formula and in the formul you put:

    ({tblCases.IsComplete} = true) and ({tblCases.CaseStatus} = 'original'))

    If you want one total for the whole report you set Reset to Never.
    Put the field in your report footer.

    Author Comment

    OK.....then to be clear, I need to SUM on the total number of cases not a count. I need to:

    Count tblCases.NumberCases
    if tblCases.CaseStatus = 'original and tblCases.IsComplete
    LVL 77

    Expert Comment

    As I said , use a running totals field as I described.
    LVL 34

    Expert Comment

    I think Peter's got you pretty well covered to get your count.  If you're trying to get a count of the records where certain conditions are true, then, as he said, you can use a running total to do a count, but only when your conditions are met.

     FWIW, the error from your original formula was because of the "and if" between your two conditions.  That should have just been "and", without the "if".

     if a and b then c      // Valid
     if a and if b then c   // Not valid

     Just to be clear, the formula still wouldn't have given you the count you wanted.  Count () gives you a final count every time you use it, as opposed to adding 1 to a count every time you use it, which seemed to be what you were expecting.

    LVL 100

    Accepted Solution

    That should work.

    You could also use a formula like

    if ({tblCases.IsComplete} = true) and  ({tblCases.CaseStatus} = 'original')) then

    Then simply add it up with a summary function.


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now