Group Summary Involving dividing in Crystal Reports - crystal-reports

I have a Crystal Report with about 9 different groups and wanted to be able to have a summary that involves dividing one value by the other.
For example (table):
Period Company Division Region State City Store Employee Sales Goal
01-2012 Ab Works Northern NW OR Ball 888 Foo 100 150
01-2012 Ab Works Northern NW OR Ball 888 Choo 175 120
02-2012 Ab Works Southern SE GA Chip 743 Bar 34 75
02-2012 Perrywee Northern NC MN Fedd 147 Bill 80 64
03-2012 Perrywee Eastern FE WV Wood 98 Tim 75 250
01-2012 Perrywee Eastern FE WV Wood 92 Karl 84 250
01-2012 Perrywee Western W CA Fub 398 Fubar 175 170
My output then looks like this:
Company Jan2012 Feb2012 Mar2012 ... YTD-Avg
Ab Works 70.3% 87.3% 87.5% 84.3%
Perrywee 93.5% 97.3% 130.3% 90.4%
Each will allow drilling down to the group below it and the value is calculated by the sum of sales for the group divided by the sum of goals for the group. As there are 14 periods and 8 groups I want to avoid having to create ~115 formuals.
Is there an easy way to accomplish this?

I've done something similar but not using Percentages. The way I thought it out is almost painful to do, but you will have drilldown capabilities. I'll post what I've come up with but if someone can modify this to make it easier, by all means.
First, create the 8 groups you want use and hide them. You will need 14 formulas to create columns for your periods. For your first period, the formula (and following periods) should look like this:
IF {table.period} = "01-2012" THEN
IF DrillDownGroupLevel = 0 THEN
SUM({table.sales}, {table.group1}) / SUM({table.goal}, {table.group1})
ELSE IF DrillDownGroupLevel = 1 THEN
SUM({table.sales}, {table.group2}) / SUM({table.goal}, {table.group2})
ELSE IF DrillDownGroupLevel = 2 THEN
SUM({table.sales}, {table.group3}) / SUM({table.goal}, {table.group3})
ELSE IF DrillDownGroupLevel = 3 THEN
SUM({table.sales}, {table.group4}) / SUM({table.goal}, {table.group4})
...
ELSE
SUM({table.sales}, {table.group8}) / SUM({table.goal}, {table.group8})
ELSE
0
What this formula does is identify what period it is, then determine what group level it is on. It then Sums up the Sales and Goal considering what the group is suppose to be on that level.
For line IF {table.period} = "01-2012" THEN, I'd set up as a parameter so it will work for multiple years.
I would rather use a function to determine what group level I was on, but all I know is DrillDownGroupLevel. It is useful but flawed if you try to do something fancy with the groups (conditional surpression) don't do a simple drilldown.
Change {table.group1} to what ever field you used for that group level. i.e. {table.company}
A drawback on this formula is every time you drill down, the DrillDownGroupLevel will change. The new level you reveal will be correct, but previous levels that still show will change.
Hope this helps.

Steps:
insert a cross-tab; company for row totals; period for column totals (set group options to 'for each month'); add sales and goal to summarized fields
preview report
right click a goal cell, select 'Embedded Summary', then 'Insert Embedded Summary'
switch to design mode (cross-tab expert); ensure order (top to bottom) of fields are #Embedded Summary, Sum of Sales, Sum of Goal
go to preview mode; right click Embedded Summary field and choose 'Edit Calculation Formula'; add the following:
local numbervar n:=GridValueAt (CurrentRowIndex, CurrentColumnIndex, 1);
local numbervar d:=GridValueAt (CurrentRowIndex, CurrentColumnIndex, 2);
if d<>0 then n/d*100
suppress the sales and goal fields
I haven't (yet) found a way to remove the extra space, however.
Sample:

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.

How to create a filter for columns in a dashboard?

I have a table which looks like this
id login_id trend_type sep oct nov
1 abc#abc.com Billing 10 34 43
1 abc#abc.com Visits 20 43 56
1 abc#abc.com Revenue 30 12 12
1 pqr#pqr.com Billing 40 23 54
1 pqr#pqr.com Visits 50 21 47
1 pqr#pqr.com Revenue 60 98 12
I want to create a dashboard where I can display graphs of all these Trend Types and add a filter for the user so they can select the month for which they want to view the graphs.
I have tried this solution -
https://community.tableau.com/thread/228965
but I wasn't successful.
Tableau really likes data that is taller rather than wider. In this case, you need to do a PIVOT on the month data. A pivot will create a column for the months and another column for the values. Your data will have more rows now but fewer columns.
When you bring the data into Tableau, on the Data Source screen, highlight the three month columns and select pivot.
You can also change the name of the Pivot Field Names (to Month) and Pivot Field Values (to Amount or another appropriate name).
Click on the orange Sheet 1 on the bottom left. Next, create a calculated field to create a full date. (Tableau doesn't know what 'sep' is.)
[Pivot Field Names] + "-01-2019"
This field just creates a string that Tableau can parse (eg 'sep-01-2019'). Now tell Tableau it is a Date field by changing the field type (click on the Abc next to the Dimension name).
At this point, you can create a viz and add filters. Here is an example.

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)

Getting data on a single row

I have a stored procedure that return the data as shown below. There is 3 rows of information for evey company. I am trying to design a crystal report to display the data on a single row as shown below under Desired Output.
How can this be done ?
Loc facility ARtype days Revenue PPD
140 Company ABC MCD 1724 4000 137.76
140 Company ABC MRA 218 8000 327.69
140 Company ABC MPD 85 7000 166.84
Desired Output
140 Company ABC MCD 1724 4000 137.76 MRA 218 8000 327.69 MPD 85 7000 166.84
group by revenue and place your field in detail where you get individual record.
Now use the below formula.
Shared StringVar a;
a:=a+<<Database field>>;
Place the above formula beside the database filed in detail and supress
Now create another formula
Shared StringVar a;
a;
Place above formula in group footer.
Edit:
Create another formula reset
Shared StringVar a;
a:=" ";
Place this formula in group header and supress the formula as this not of user importance.
You can use below simple steps,
1] Assuming you are putting your data in detail section, go to Section Expert of detail section and check the checkbox having label Format with Multiple Columns
2] This will print your data the way you are expecting. For additional formatting, you will find layout tab generated once you check the checkbox. In that layout you can set the width of detail lines as well as gaps between lines etc.
I hope this helps!

Summarizing each subgroup in Group Footer - 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.