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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Distinct count formula

Status
Not open for further replies.

hmoe

Programmer
Mar 10, 2006
9
US
I am a fairly new user to Crystal and I'm creating a summary report that keeps track of the number of orders received for a particular credit card. I created the first couple of columns using running totals and I inserted summaries to display the percentage of usage by credit card. That part was pretty simple for the first percentage because there isn't a condition in my running total so I was able to duplicate what the running total was doing by using a summary and displaying as a percentage. But this is where the difficult part comes in. Some of the columns have formulas in the running totals and I'm unable to create summaries for these columns because you can't enter formulas when using summaries. now I'm trying to figure out how to write a formula that will similate what the running total is doing but add the additional condition in it. If I was able to write SQL to get the answer I would code a simple statement as follows:

Select distinct(a.res_nbr)
from table a, table b
where a.res_nbr = b.res_nbr
and b.fraud_type = 211

Is there a way to use the distintCount function in Crystal to get this answer?

I tried to write this function and I received an error:

NumberVar chgbckcnt := DistinctCount{CHARGE_BACK.RES_NBR}) where fraud_type = 211

if chgbckcnt <> 0

then
({#RTchgBck} / chgbckcnt ) * 100
else
0
 
You can write SQL, dependi9ng upon your software version, which should be included with any post about any software product.

Since you didn't bother to post this basic info, I would suggest that you use a Running Total and select distinctcount and in the evaluate->use a formula place:

{table.fraud_type} = 211

Then you can use the formula:

if {#MyRunningTotal} <> 0

then
({#RTchgBck} / {#MyRunningTotal}) * 100
else
0

-k
 
Thanks for the help. I apologize for not stating the version. I am running version 10. I tried creating the running total you mentioned above , but the evaluate doesn't give me the option to insert another running total inside of a running total. The answer to my question doesn't have to be a running total or a distinct count. I just want it to work. I'm just trying to figure out how to get the percentage. The calculations are all running totals that appear in the group footer and the totals are in the report footer. I need the percentage to read 66.7%, 0%,33.3%. I've tried several things and the way that is working now, is it has 100% on the Visa line and 33.3% on the JCB line. It looks like it is dividing 2/2 and then 1/3. This is what the columns I'm working with look like:
Tender Type # Orders $Orders % by Type
Visa 2 3,000
Discover 0 0
JCB 1 1,500
Total 3 4,500
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top