How to get the COUNT of rows in Crystal Report - crystal-reports

I have a data in database which gives me 8 rows based on date range out of which 5 are HCT, is there any formula in crystal report where I can get that count of those 'Abbr' ?
I am comparing HCT text from Dynamic report selection, I need to know can we create a variable which gives us count of 'Abbr'.
like for
HCT should return 5
US should return 2
RN should return 1 value.
UPDATE 1:
Here is what I am trying to do. I have secondary selection criteria as Dynamic report along with date range.
in the above example I have selected only "HCT", now even though sql data is returning 8 rows (HCT,US,RN) I need only the HCT count i.e. 5.
If I select "HCT" and "US" in the secondary criteria then I should get count of both HCT and US i.e. 5 + 2 = 7.
if I am not selecting anything then it should return 0, so irrespective of the data from DB, the value should be summed based on selection of my criteria.
am I clear enough?

Use Running Totals.
Specifically, make a Distinct Count running total for each Date Range code. You can set a formula in the Running Total Wizard to only evaluate records where, for example, {DateRange} = "HCT"

I found the solution for my question, I am just putting it here so that someone may help for the above mentioned formula.
This is what I did
Created a Formula(not running totals) by name SumOfSkills
if({Command.GlobalSkillAbbr} in {?GlobalSkill}) then 1 else 0
here Command.GlobalSkillAbbr is my "HCT" and '{?GlobalSkill} will contain all Global skills.
and used another formuala to sum it up.
Sum(SumOfSkills)
which gives me desired output.

Related

Suppress records in grouped section between first two and last records in Crystal Reports

First, I am using Crystal Reports 2011. I need to suppress records in a group that fall between the first two records and the last record. In other words I only want to see record number 1 and 2 and the last record. I can easily suppress records that are not the first two, but getting the last record to not be suppressed has me at a standstill. I am creating a report where we want to only show the first, last and next-to-last time we purchased items. Some items have been purchased many, many times. I have the report grouped by part number, then all the dates we purchased the part (and other data) are in the group details. I have tried using a running total count, where I simply suppress details that are not 1 or 2, but the last record count varies depending on how many times we have purchased the item, so I don't know what the last count number will be for each group to use it in the suppress formula. I have also tried with declaring a variable and increment the variable for each record, but end up with the same problem as using running total count. Anyone have a suggestion?
To clarify my question a little further, I am sorting the group by date, most recent date first. So record count 1 is the last time we purchased and record count 2 is the next-to-last time we purchased. So by using record count I can suppress records that are not 1 or 2. The problem comes when trying to figure out how to not suppress the last record (which is the first time we purchased). Below is a link to a pic of what my report looks like with nothing suppressed. For this part I would want to suppress all records except 1, 2 and 5. But again, the last count number will change per part number depending on how may times we have purchased the part.
Help is greatly appreciated!!!!
Report cropped image
Using Crystal syntax you can test on OnLastRecord which returns true if you are on the last record or false if not. Simply suppress accordingly.
EDIT:
As pointed out by jmears, the above won't work for multiple groups of differing products.
Instead you can add a running total field to count each record within the group, reset on change of group. Then suppress the details based on the running total not being 1 or 2 (for the first two records) and not equal to the total count of records for the group.
Here's an example suppression formula, where {#rt} is the running total count of records. It uses the Count function to return the total count for the group
not({#rt} = 1 or {#rt} = 2 or {#rt} = Count ({fieldToCount}, {GroupField}))

Using running totals in formulas - Crystal reports

I have created a set of running totals looking for specific fields in a database.
If these fields are located, a subsequent sum is performed to calculate the total for that field. e.g. Field to Summarise - DB.Field.Value-Sum. Evaluate - Use a Formula-Field Name ='1'
This sums the totals for this field. The issue is that I have many running totals doing this, and what I want to do is add these together to provide a total for all of these. Currently I have a formula that uses each field with a '+' between each. This appeared to work fine, but when tested against a record where some of these fields are blank, the subsequent formula displays nothing.
Any advise on what I should do here/ am doing wrong?
Thanks
It sounds like a null record (empty value) is breaking your running total. You have a few options
Use a formula to check for, and replace a null value with another value (Zero, for example) and then use that formula in your running total calculation
if isnull({Command.Decimal}) then 0 else {Command.Decimal}
Use a SQL expression to replace null with another value Isnull(Tablename.Columnname,0) - use this in your running total
On the running total, under "evaluate" select Use a formula and use this formula not(isnull({tablename.columnname})) -- If the record IS null, the running total does not evaluate it. It will be ignored by the running total.

Return 0 value if Details duplicated

I need your help in creating crystal report.
I have a formula in details section that computes working time.
How do I make the value return 0 if it is duplicated?
Here's the scenario
Name Time (Hours:Minutes)
John 1:20
........ 3:30
........ 3:30
Total Hours -> ?
My problem is I dont want to use the duplicated values (3:30) like shown above. I want a total hours for 4:50.
you have two options:
check the option in Database tab.. Select Distinct Records so that duplicate records will be eliminated.
If you don't want to use the first option then to calculate use Running Total so that you sum only those that are distinct...
Create running total something like Do sum only after change of time value
You can use the function "previous" to compare the current value with the previous value, but it works only with fields.
But i am not sure if i understood, you may be more precise about your question.
1) make a formula called "hours" or some other name
if not isnull(previous({Result.Time}) and {Result.Time} = previous({Result.Time}
then 0
else {Result.Time} /* you have to assure the same return type */
2) let the "total hours" be a sum of the formula "hours"
Note that it will work only if the rows are ordered by hours.
The result is the same of using a running total fields as purposed by Siva.

Crystal Reports and Adding values

I am using Crystal Reports XI and I'm trying to add a particular column if one column or another column is set to one.
Here is the current preview:
Username (GROUP 1)
MONTH (GROUP 2)
DATE SUBJECT TOTAL_TIME
End of group 2
End of group 1
Now I want to add the values in total_time if one of the two hidden fields contain 1 (true).
I tried using sum() function but it didn't work as it added all the times together.
I'm still new to Crystal Reports and I tried searching on google but nothing came up similar to what I need.
Any help would be greatly appreciated.
One alternative that I can suggest, You can use Parameter fields on your report.
Do the calculation on Code behind and set the calculated sum to parameter field on Page_Load event of Crystal Report page.
This parameter field will be used to display the sum on report page.
Please check this link to see
-How to create Parameter Fields:
http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/en/CrystalReports_dotNET_SDK/crsdk_net_doc/doc/crsdk_net_doc/html/crtsktutorialscrvparametersdiscretecreatingreport.htm
-How to set values in Parameter Fields:
http://msdn.microsoft.com/en-us/library/aa289936(v=vs.71).aspx
Your best option will be use "Running totals" by this way you can control the flow by keeping a condition to sum when the required column is 1.
Did you think about small trick? You wrote: I want to add the values in totaltime if one of the two hidden fields contain 1 (true).
Under these circumstances you can calculate helper field Total_Time_Conditional using formula:
Total_Time_Conditional = IIf(HiddenField1 = 1 or HiddenField2 = 1, 1, 0) * Total_Time.
This will multiply Total_Time
by 1, if any of hidden fields is 1
by 0, if both hidden fields are 0
Calculating Sum(Total_Time_Conditional) will give you expected result.

JasperReports group by all - display row even if nothing returned

I am trying to get JasperReports to mimic the SQL GROUP BY ALL functionality. I am grouping by MY_BOOL which can either by 0 or 1 and I am displaying the value, and a count on the number of rows in my report. However, I want to display a row for each, even if there are 0 rows for one of the values. So for example, if my query returns ten rows, and MY_BOOL=0 for all ten, I would like to see:
MY_BOOL | COUNT
0 10
1 0
How can I accomplish this in JasperReports?
EDITED:
It sounds like you need 2 variables and no groups.
$V{MY_BOOL_0} counts all rows where $F{MY_BOOL} is 0. $V{MY_BOOL_1} counts all rows where $F{MY_BOOL} is 1. The initial value of each variable is 0, so it doesn't matter if there are zero rows with $F{MY_BOOL} = 0.
Display the 2 variables in the title (or summary or wherever) to provide your 2 "grouped" subtotals.
Note: These 2 variables don't use groups at all, but they would be compatible with groups. For example, you could calculate the MY_BOOL_0 and MY_BOOL_1 values for each month if you group on months.