Getting data on a single row - tsql

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!

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.

Change groups on new page

I need to create a summary page in crystal reports where it groups all the details with the same ItemName and calculates the totals
Data Example:
Balls 50
Balls 75
Food 10
Dolls 45
Food 68
On the last page in the report I need it to say
Balls 125
Food 78
Dolls 45
The report is already grouped by another detail, is there anyway to change what the report is grouped by on the last page?
Insert a cross-tab object in the report footer. Use the text field in your example as the 'row' field in the cross-tab. Use the numeric field in your example as the 'summarized' field. Leave the 'column' field blank.

Getting the values of the maximum record

I am facing some difficulties while developing a report. The problem is that I am getting a number of values in the Details section and I want only to display the record which it is having the maximum event number for each group (one record to be shown for each group).
My report structure is:
GH1:{Deal_NO} 1 -- Suppressed
Details:{Deal_NO} {Amount} {Event_no} {Comments}
1 1000 222 Rate
1 2345 655 Principal
1 444 111 Sell
GF1: {Deal_NO} -- Suppressed
So, my result should be:
1 2345 655 Principal
So, please instruct me on how to do that.
I tried to define in the Group Selection under Select Expert:
{Event.Event_no}=maximum({Event.Event_no},{Deal_No}), but some deals were disappeared.
You can't use that logic with record or group selection. Instead, use the logic you have but use it to suppress the Details Section. So,
//Suppress Details if the current record is not the record with the
// maximum amount for the group
{Event.Event_no}<>maximum({Event.Event_no},{Deal_NO})
Now, when you run the report every record will be suppressed except for the one with the maximum amount per group.

Require multiple pages for a single bar chart in Crystal Reports 2008

I am creating a bar chart where the values are the maximum of an AVE_ZSCORE field, and this is set as "on change of" a PARTICIPANT_CODE field. On any given occasion, I could have up to 250 records in this chart and therefore I need to split the chart over a number of pages. This number of records is dynamic however, and can range between 150 and 250 records.
I have tried the solution in this thread http://www.tek-tips.com/viewthread.cfm?qid=1257385 and I've followed the instruction as best as I understood (please bear in mind that I'm quite new to Crystal Reports). I created a formula, inserted it in the details section which I then suppressed, then inserted a group on that formula, and inserted the chart in the group footer section. The formula I'm currently using (which I called "chart") to test this out on 4 records is:
WhileReadingRecords;
numbervar cnt := cnt + 1;
if cnt in 1 to 2 then 1 else
if cnt in 3 to 4 then 2
My problem is that the output of this results in 3 graphs of the following instead of 2 graphs containing 2 records each:
a group output of 0.00 which has all 4 records (B2, BB, KK, MM) in
one graph
a group output of 1.00 which has only one of the records (BB)
a group output of 2.00 which also has only one record, which is the
same record of the previous graph (BB)
If I change the formula to display as follows:
WhileReadingRecords;
numbervar cnt := cnt + 1;
if cnt in 1 to 4 then 1
Then the output becomes
a group output of 0.00 which has all 4 records in one graph (B2, BB,
KK, MM)
a group output of 1.00 which has one record (BB)
So firstly, I don't understand the formula that I'm using or how it works, and secondly I have no idea how to get this working so that I can easily specify the number of columns per chart
Unfortunately it's hard to say something without total understanding of your report layout. Some screenshot will easy things alot. As nothing yet specified I expect you have only one (mentioned) group in your report.
To achieve you goal you should render your chart as many times as different group values will be. This is how details section of group is rendered. Not footer or header. As chart can't be added to details section additional dummy group should be created. So in result there will be 2 groups:
Outer group (#1) will be based on your formula field and have no header/footer
Inner group (#2) will be used to show chart in either header or footer
Group #2 can be based on same formula as group #1 (or any other formula/field, it shouldn't matter).
Btw, instead of calculating count manually, like in your code
WhileReadingRecords; numbervar cnt := cnt + 1;
You can use Running total fields, with type of summary count on any field you want to control. Such fields are very customizable, so you'd like them.

Group Summary Involving dividing in 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: