Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you get a mathmatical 'sum' of String variables/formulas?

Status
Not open for further replies.

Drakhan

Technical User
Jun 3, 2002
67
US
I have these two columns of string variables, client and prospect (see below), I would like to get a sum of each column:

C............P....
-------------------
SC................
SC................
SC................
NSC...............
NSC...............
............HPP...
............LPP...
.............D....
.............U....

The periods above represent a space...for whatever I reason I could not space these out properly...

Anyway, how do I get a sum of each column...one for C and one for P?

Currently the values in columns of C and P are @Customer and @Prospect - both being formulas. Any ideas? Thanks!
 
I assume you mean a count since you cannot sum text.

Right cick on the field in question, select insert, select summary or grand total, whichever you desire, and make it a count operation.

Repeat this for the other field and you are done. Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
Assuming these formulas return "" in the "empty"
cases, a simple count operation will not solve the situation since it will count all rows.

Instead, use a Running Total with a condition
or create a formula:

IF IsNull({@Prospect}) THEN 1 ELSE 0

and SUM (not count) that formula to produce the count.

Do the same for the other formula.

hth,
- Ido
CUT (Crystal Utilities): Shortcuts for e-mailing, exporting, electronic bursting & distribution:
 
Ok the "C" column generates its data (SC or NSC) by the following @Customer formula:

if {CONTACT2.UCLASSIFIC} in ["SC", "NSC"]
then {CONTACT2.UCLASSIFIC} else ""

The "P" column generates it data (LPP, HPP, D, U, R) from the following @Prospect formula:

if {CONTACT2.UCLASSIFIC} in ["LPP", "HPP", "D", "U", "R"]
then {CONTACT2.UCLASSIFIC} else ""

I am also hide if there are duplicates by date (i.e., there could be several calls on the same day...I just want to see only 1 instance in my report per day). So, the report itself looks good, however, it just can't seem to total each invidual column. The closest I've been able to get is count that totals ALL of the calls, both hidden and shown...

The criteria for the running total is as follows:

Summary:
Field to summarize @Customer
Type of summary count

There are NO null fields...each field is filled in...I thank you for your help! You all have been great!
 
Ido,

Yes, I tried you suggestion as you requested. Thank you for the input. However, there is no "Sum" option in the running total, I can only use "count", "distinct", "maximum", "minimum", "nth largest", "nth smallest", etc.

I put your forumla in the 'Use a formula' in the 'Evaluate' area of the running total. It just returns zero.

The closest I've been able to get with the running total is using a 'count' on @Prospect and having it 'Evaluate' on Company name (this however also includes the Customer column in its total - which also includes all the previously suppressed ones as well).

In a nutshell, I am no farther along on making this work than yesterday, but I do appreciate your help! :)
 
dgillz,

Thank you for the response. I tried your suggestion of using summary or grand total, it did count them, however it counted what was in BOTH columns. That is, every instants in Customers and in Prospects. This also included anything that was suppressed. The report generates 21 records, I really am only interested in 14 total (I supress, for example, duplicate calls to the same customer on the same day).

Is there any way to look at for a variable in a column and count it? I guess I never thought it would be this hard to calculate the amount of items in a column...thank you.
 
Drakhan,

Having looked at the solutions offered to you, IdoMillet has got you pretty much there. It's difficult to see where you are still encountering a problem, because it sounds as if the running total you created is doing what you'd want. Crystal won't give you the option to SUM if you are focusing on a field which is not numerical.

IdoMillet's way should work for you as far as I can tell, but if you're still encountering problems;

Create a formula, like;

//***
whileprintingrecords;
numbervar prospectcount;

if IsNull({@Prospect})
then prospectcount
else prospectcount+1;
//***

Place that formula in the detail section, or whichever section you have your C and P variable fields. You might want to suppress this counter field.

Then, where you want to display the value of the count;

//***
whileprintingrecords;
numbervar prospectcount;
//***

If this count is by group, remember to reset the counter by creating a formula which sets the counters to 0

//***
whileprintingrecords;
numbervar prospectcount := 0;
//***

and place this field in the group header where you need the variables reset.

Again, this solution is to give you a COUNT of the fields in your report. You mentioned SUMming a couple of times, but you really can't sum the values in either of these two columns.

Naith
 
On supressed records, all suppressed records will evaluate in any summary operating including your counts. You most likely need to dump your supression formula nad instead exclude the erecords from your report altogether with a record selection formula.

The other alternative, as already mentioned, is running totals. Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
Thank you all for the help! I did manage to figure it out with all your help. I created a forumlas like this:

IF IsNull({@Customers}) THEN 0 ELSE
IF ({@Customers}) = ["SC", "NSC"] then 1

and

IF IsNull({@Prospects}) THEN 0 ELSE
IF ({@Prospects}) = ["HPP", "LPP", "U", "R", "D"] then 1

It creates the counter ok, i.e. marks the field with a "1". However my problem now is that when I go to do a "grand total sum" of the "1's", it somehow includes all of the suppressed "1's" as well. My calculations are off a little. Let me provide a brief example:

Without suppression

C P Client Name Date
-------------------------------------------------
SC Client 1 5/20
SC Client 2 5/21
HPP Client 3 5/22
Client 3 5/22
LPP Client 4 5/23

2 3 TOTAL = 4

With suppression

C P Client Name Date
-------------------------------------------------
SC Client 1 5/20
SC Client 2 5/21
HPP Client 3 5/22
LPP Client 4 5/23

2 3 TOTAL = 4

Notice Client 3...it was duplicate entry (b/c they were called on twice in the database). All I want to see is one call on Client 3 (for example) per date. It counts the Client Name column to get the TOTAL number. It uses a sum of the above formula's to get the numbers for C and P columns. To see how C and P are determined, see the above post. What I'd like to see, while suppressing the duplicate entries for the date is:

C P Client Name Date
-------------------------------------------------
SC Client 1 5/20
SC Client 2 5/21
HPP Client 3 5/22
LPP Client 4 5/23

2 2 TOTAL = 4

How is this done in Crystal? Again, thanks for your input on this matter!!
 
Create a Running Total summing the formula but set the EVALUATE option to evaluate for each Client ID (if you are grouping by Client ID, this option should be available to you in the Running Total dialog.

Cheers,
- Ido CUT (Crystal UTilities): e-mailing, exporting, electronic bursting & distribution of Crystal Reports:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top