Solved

Crystal Formula to "conditionally count/sum"

Posted on 2016-11-28
3
59 Views
Last Modified: 2016-11-28
Gurus,

I created a series of reports that include "conditional count/sum" formulas like this:

if {TBL_HISTORYTYPE.NAME} = "Client Visit Completed" then 1 else 0

Unfortunately, I recently found out that some of the records are repeating because of another table that's tied to the History table.  (CONTACT -> HISTORY -> HISTORYTYPE) (My counts are incorrect if multiple contacts are included).

I'm trying to avoid rebuilding all of these reports by adding subreports for the contact information.

Is there a way to incorporate the HISTORY.HISTORYID field (string) in the formula to only sum if the HISTORYID has changed?

Also, my "totals" have to appear in the Report Header - so I don't think a "running total" will work.

I appreciate any ideas!  Thanks in advance
0
Comment
Question by:SStroz
  • 2
3 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 41904828
You are correct that a running total won't work.

Try this

if {TBL_HISTORYTYPE.NAME} = "Client Visit Completed" then 
    {HISTORY.HISTORYID}

Open in new window


Do a distinct count on that field.

mlmcc
0
 
LVL 7

Author Closing Comment

by:SStroz
ID: 41904870
Shoot - I closed this too soon.

I should have mentioned that I have 3 formulas like this:

if {TBL_HISTORYTYPE.NAME} = "Client Visit Completed" then {HISTORY.HISTORYID}
if {TBL_HISTORYTYPE.NAME} = "Prospect Visit Completed" then {HISTORY.HISTORYID}
if {TBL_HISTORYTYPE.NAME} = "Trial Visit Completed" then {HISTORY.HISTORYID}

It doesn't look like it's counting correctly.  

It looks like Crystal is counting a "1" where there should be a "0".  ??


Any ideas?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 41905141
I was afraid that might happen.

It is counting the ones that don't match as 1 since the return is not null

Try it this way

Create a formula
Name - NULL
Formula is nothing just save an empty formula

Change the formula above to

if {TBL_HISTORYTYPE.NAME} = "Client Visit Completed" then 
    {HISTORY.HISTORYID}
Else
    {@NULL}

Open in new window


That will result in NULL for the non-matching and DistinctCount will ignore the NULLs

mlmcc
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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