• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2616
  • Last Modified:

Crystal - Count if with multiple qualifiers

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})
0
dsabine
Asked:
dsabine
1 Solution
 
peter57rCommented:
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.
0
 
dsabineAuthor Commented:
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
0
 
peter57rCommented:
As I said , use a running totals field as I described.
0
 
James0628Commented:
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.

 James
0
 
mlmccCommented:
That should work.

You could also use a formula like

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

Then simply add it up with a summary function.

mlmcc
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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