Summarizing each subgroup in Group Footer - Crystal Reports - crystal-reports

I'm trying to work on a report for a client. Basically I need something like such
Group 1: Customer ID
Group 2: Truck ID
CustID Vehicle ID Detention Time
------ ---------- --------------
ABX 100 60
35
20
TOTAL: 115
200 80
15
TOTAL: 95
300 10
TOTAL: 10
TOTALS FOR CUSTOMER ABX
100 115
200 95
300 10
Is there anyway to accomplish this without a subreport? I was hoping for a "summary field" that I could summarize more than just a single value.
Thanks!
(FYI using Crystal Reports 2008)

Use a crosstab; place it in the report-footer section.

There might be a better way to do this, but the one that comes to mind is to use two arrays: One to store the truck ID and another to store the corresponding total. In each inner grouping (TruckID), just tack on another array element and store its total time. To display, you could cast the values to strings, attach a newline character after each entry, and set the field to "Can Grow". So altogether, you'd need three formulas: one to initialize the arrays (in GH1), one to update the arrays with sum({truck.time},{truck.ID}) (in GF2), and one to display each entry (in GF1).
With that being said, CR has terrible support for containers... You're limited to 1-dimensional, non-dynamic arrays that are gimped at 1000 items max. It doesn't sound like these would be big problems for what you're trying to do, but you will need to redim preserve the arrays unless you know ahead of time how many trucks you'll have per customer.

Related

Crystal Reports SUM formula help. Don't SUM values with specific IDs

I have a table with rows of Invoice data and I want to SUM the values of all line items where the Item ID is not equal to 0000 or 9999.
The Item IDs I want to exlcude 0000 and 9999 never change.
ITEM ID
NAME
WORK VALUE
TOTAL COMPLETED
0000
HOLD 1
0.00
1,234
1234
MATERIAL A
333.00
76.00
1235
MATERIAL B
567.00
7043.00
1236
MATERIAL C
981.00
321.00
1237
MATERIAL 4
430.00
5445.00
1238
MATERIAL 5
10.00
897.00
1239
MATERIAL 6
18.00
654.00
1240
MATERIAL 7
882.00
3.00
1241
MATERIAL 8
777.00
65.00
9999
ZY HOLD
0.00
111.00
So the value returned in the report from the example above should = 18,502.00 not 20,847.00
I have tried:
IF NOT((TONUMBER({Invoices.InvoiceItems~ItemNumber}) = 9999))
THEN
(SUM({Invoices.InvoiceItems~InvoiceValue})+SUM({Invoices.InvoiceItems~TotalCompleted}
but this doesn't work, it still sums the value from the 9999 line item
I would create a Running Total Field to accomplish this.
A Running Total Field works very similar to the Summary Field, but allows a lot more control over which records are evaluated when summarizing the data. To setup a Running Total Field for your needs try the following steps.
Create a new Running Total Field.
Set the "Field to summarize" to use the Total Completed column from your database. Set the "Type of summary" to SUM.
Set the radio button in the "Evaluate" section to "Use a formula", then click the X-2 button to create the formula that will determine if a row of data should be included in the sum or not. Whatever formula you enter here will need to return a boolean value. When this value is TRUE, the row's data is included, and when it's FALSE the row's data will be excluded. I would use the following formula here: TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 9999 AND TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 0000
The last thing to do is the setup the Reset conditions for the Running Total Field. This would be used if you were grouping data in some fashion such as by Customer and would allow you to sum the data for a single customer, then reset to zero for the next customer. If you are not using any grouping you can probably just leave this set to "Never".
Click OK to finish. :)
At this point all you need to do is drop the Running Total Field you just created into your report. Be mindful about which sections you place this field within though. If you place it in a header section, you will likely find it doesn't add in the last record in your dataset because the report hasn't printed it to the details section yet. I recommend placing Running Total Fields in Footer sections to avoid this nuance.
I hope this helps! And if you do have some grouping levels that you need help with setting the reset conditions just let me know what the grouping levels are for your report and I can update this answer for you.
You can create a new formula similar to yours:
IF TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 9999
AND TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 0
THEN {Invoices.InvoiceItems~TOTALCOMPLETED}
ELSE 0
and then just sum this formula field up.

BIRT Mathematics on data set

I am pretty new to Birt reporting, i can make simple charts and tables, bet when it comes to some calculation of values from data sets - i have no clue in which direction should i watch.
For example i have this simple data set:
count1 count2 max type lenght
616 3858 21 STEEL 20
723 4432 14 STEEL 40
854 5869 21 ALL 20
838 5225 14 ALL 40
And i would like to have Birt to calculate approximately this:
SUM(count2)/SUM(count1) WHERE type=ALL
so this
((5869+5225)/(854+838))
My question would be how could i get there. At this point i think i would need just the right direction how these kind of operations could be made.
Thanks in advance.
I presume you want to display this value somewhere on the report, like at the bottom of a table where this data is presented. If this is the case then add an aggregation data element to the footer of the table where the data is displayed. In the aggregation data element you will have the opportunity to specify an expression SUM(count2) and a filter condition [type=ALL]. You can then do the division in another data element.
If you want to simply compute the value you described you you could do it with SQL, i.e. SELECT SUM(count2)/SUM(count1) FROM myTable WHERE type='ALL'. You would have to provide the data to the report as a data source which could be in the form of an excel spreadsheet, *.csv, database connection, etc.
So there are a few ways to do this depending on what your requirements are.

how do i subtotal on groups based on a condition

My report is grouped on clinic, staffname with subtotals by clinic. I need to count patients by staff where they had more than 1 admit date. I can get the correct grand total, but on the detail and subtotals, it is a progressive number.
Here's what I want
clinic1
staffname1 10
staffname2 95
subtotal 105
clinic2
staffname3 6
subtotal 6
grand total 111
Here is what I get:
clinic1
staffname1 10
staffname2 105
subtotal 105
clinic2
staffname3 111
subtotal 111
grand total 111
A lot of this may depend on the structure of your data, e.g., what is in your "detail" level. I am also assuming that you want to count of how many patients had more than one admit date, not the total number of admits for patients with multiple admits. Given that, and assuming a patient will only appear once per admit date, then this should work:
Group by patient also, so it's clinic -> staff -> patient, but suppress that group.
Create a formula to count if the number of records in each patient group is more than 1, something like this: if count({patient},{patient}) > 1 then 1 else 0
Take the formula you just created, and use it to make a summary field wherever you want a total, e.g., in the staff head it will give you a count or that staff member, in clinic it will do so for clinic, etc.
Something else to consider: I'm guessing this could be intended to gauge staff on their quality by seeing how many patients had to seek additional treatment. Even if that's not the full intent, whatever this is being used for could be skewed by staff encountering more/fewer patients. For example, staff that have 10 readmits out of 100 visits would look worse than someone who only had 5 readmits, but had also only seen 20 patients.
So: Along with the metric on which you are requesting information, I would also add a ratio metric. In the staff header, this would be straightforward: count({patients}) / distinctcount({patients}) which will give you the ratio of distinct to repeat visits. Keep in mind also that this could skew high for a staff member that had, for example, 50 patients, but one of them came back a dozen times.
To get the count of the fields that has Greater than 1.
Assuming the count field is a database field and value coming directly from database
Create a formula #Count and write below code. Place the forumla in details.
:
if(databaswefield.count > 1)
then 1
else 0
Now take the summary of the #count formula in required group footers.
Let me know if you are looking for something different.
Edit..............................................................
If I got your comment correctly.
Though you take distinct count you can use that in your calculations by storing the value in a shared variable. Something like below and you can retrive value from that variable
Shared Numbervar count;
count:=distinctcount(patientid)

Ignore Duplicates in Count

I have a report in Crystal that won't total correctly.
I have groups set up as show below:
Date
Hour
Item
The actual data is:
8/20/2013
9.00
5411400
5411468
5411497
10.00
5411600
5411671
14.00
5411468
5443140
15.00
5441468
16.00
5443714
5443764
5443813
What I need is a count of each of the 5xxxxxxx numbers for each group, but only counting duplicates once for the whole set. How is should appear is:
Hour - Total
09 ------ 3
10 ------ 2
14 ------ 1
15 ------ 0
16 ------ 3
Is this possible in Crystal? I've tried creating a formula, a running total (with and without a formula), and various summations (using distinct and non-distinct counts), but none of them produced the right result. It seems so far that I can only make Crystal calculate distinct counts per each subgroup containing the 54xxxxx numbers and not via the hour.
I am confused with below line as you said you want the count of 544xxx but here in 9th hour there is no 544**
What I need is a count of each of the 544xxxxx numbers for each group, but only counting duplicates once for the whole set. How is should appear is:
Tell what exactly you need. Will try to help
I found the solution: In this particular report, there was a sub SQL query that was causing the duplicates. I changed the sub-query to not generate an "hour" for each entry but instead for each order.

Crystal Reports - Formula to count groups/How to create an average based on sums

I am working on a report that shows Part Numbers with multiple Purchase Order numbers, Order Quantity and Shipped Quantity. First I grouped Part Numbers.
Part # 21104-2F PO # S7CEO Order Qty: 10 Shipped Qty: 0
PO # S7CEO Order Qty: 10 Shipped Qty: 0
PO # S8LVU Order Qty: 5 Shipped Qty: 0
Sometimes we split jobs within a purchase order. For example: (look above at PO # S7CEO) you order 20 of part # 21004-2F. We separate it into two lines (or jobs) of 10 parts per job. In this report I only want to see that you ordered 20. To achieve this, I created a second group for Purchase Order numbers and inserted a sum so that way I only see that you order 20 parts.
Part # 21104-2F PO # S7CEO Order Qty: 20 Shipped Qty: 0
PO # S8LVU Order Qty: 5 Shipped Qty: 0
My dilemma: I need to show an average based on how many parts you ordered (so average of the 20 parts, not the 10) but CR is giving me an average based on the 10 parts.
How do I create an average based on sums?
I tried using a formula to calculate the sum then divide by line count. There are 3 “lines” but once I grouped and inserted a summary, there are 2 different purchase orders. The line count formula is counting "3" lines. I want it to count how many groups I have so it will come up with "2". Then I will be able to divide "groupcount" (2) by total order qty and that will give me an average. Is there a formula that will help me achieve this?
Thank you in advance!
Yup, Count counts all the records. Use DistinctCount, which counts the values instead:
Sum({OrderQty})/DistinctCount({PO})
That should give you 2 instead of 3 in the denominator.
As long as you're outputting the data into the group footer, you can use a SUM(shipped quantity)/COUNT(PO #) to get the average parts/shipment.
e.g.
Two level grouping on Part # (group #1) and PO # (group #2). You'd output the actual data in the Group Footer #2 field. To do your average, you'd add two summary values in that footer: SUM(shipped quantity) and COUNT(PO #). Then a simple formula field to do SUM/COUNT of those two values, and you've got your average parts per shipment value.