Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Basic Question regarding counting Post Reply Post New Topic
Author Message
jonberardi
Newbie
Newbie


Joined: 24 Jun 2008
Location: United States
Online Status: Offline
Posts: 6
Quote jonberardi Replybullet Topic: Basic Question regarding counting
    Posted: 25 Jun 2008 at 12:12pm

I am new to CR/Reporting and have a fundamental question:

 

My dataset includes a series of courses, each course has a specific category {Courses.Course_Level}.  How can I create a custom formula that simply counts the number of courses within a particular category? 

 

Having no idea what to do, I attempted the following and failed miserably:

 

if {Courses.Course_Level} = "MHS" then COUNT ({Courses.Title})

 

You help is most appreciated.

IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 25 Jun 2008 at 1:31pm
I dont know the report design nor specific version of CR. so it is hard to give a specific solution.  A couple of general solutions are to create an SQL command to count the items and then group them by item you want counted. You would then make the necessary changes in the report layout to present the count.
 
If there are a limited number of the course level you could use Running Totals for each of the course levels and then use the formula button in the running total form to set the value to count.  It essentially is a true statement.  If value is true then count kind of thing.
 
You could always create manual formulas which takes  three formulas you place at the appropriate place on the report design. For example, the Report Header, Details and Report Footer. You create shared variable and use the the WhilePrinting to set which pass the count is to occur. The report header creates a shared variable then set the value to 0. The details repeats the creation of a shared variable of the same same name, sets the logic for the count and the adds 1 to the shared variable. These first two formulas are suppressed and finally the report footer formula creates a shared variable of the same name as the report header and details, then return the variable which is the count. It works like this
 
Header  x = 0
Details   x  = x + 1
Footer    x
 
Hope this will help, the CR help file offers more complete discussion of the later two choices.
 
Regards,
 
John W.
IP IP Logged
Magman
Newbie
Newbie


Joined: 24 Jun 2008
Location: United States
Online Status: Offline
Posts: 6
Quote Magman Replybullet Posted: 26 Jun 2008 at 5:06am
i wrote this in Basic Syntax, not Crystal Syntax.   I think what you are doing can be accomplished by grouping and doing running totals, but here is a function code none the less that will do it.
 
Global x1 As String
Global y1 As Number
Global y2 as Number
x1 = {Field that contains data to count}
if x1 = "Item1 to count for" then y1 = y1 + 1
if x1 = "Item2 to count for" then y2 = y2 + 1
formula = ToText (y1) + "= Name of Item1  " + ToText (y2) + "= Name of Item2"
 
 
The above code is good if your are only looking at 1 field, if you are looking at multiple fields such as these: 
 
How many Horror and Zombie were there?
How many Musical and Rock were there?
 
Horror, Zombies
Horror, Aliens
Horror, Demons
Musical, Classical
Musical, Pop
Musical, Rock
 
 
Global x1 As String
Global x2 as String

Global y1 As Number
Global y2 as Number

x1 = {Field that contains Main data to count}             'ex. horror
x2 = {Field that contains Sub data to count}              'ex. Zombies
 
if (x1 = "Item1 Main" and x2="Item1 Sub)  then y1 = y1 + 1
if (x1 = "Item2 Main" and x2="Item2 Sub)  then y2 = y2 + 1
 
formula = ToText (y1) + "= Name of Item1  " + ToText (y2) + "= Name of Item2"
 
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.