crystal reports sum only last item in detail - crystal-reports

I wish to display in the group footer the sum of the sold qty column (which is easily done) and then only the last value of the on hand qty column.
I think a variable can do this, but not sure how to do it as I'm new to Crystal and its variables.
Here is an example
Sold qty On Hand Qty
details 1 5
2 3
============================================
GF Total 3 3
============================================
details 6 10
3 7
============================================
GF Total 9 7

Put the field {yourTable.OnHandQty} in the group-footer.
This will show the last detail value and will work as long as there's no suppression on details.
Note: The "last record" is determined by the sort within the group. This means that if the sorting is changed, the wrong value will be displayed.

Yes !! You can do this using variables.
Step 1: Create a Formula Field Named as OnHand
OnHand
shared numbervar OnHand;
Onhand := (Your Table Field) + Onhand +;
Place this one in Details section and suppress it (Right Click
Formula --> Format Field --> Common --> Supress)
Step 2 : Create one more formula to display the result
PrintOnHand
shared numbervar OnHand;
OnHand;
Place this formula in Group Footer
Step 3 : Create one more formula Clear
Clear
shared numbervar OnHand;
OnHand :=0;
Place this formula in group Header and suppress it. (This is to clear the Onhand
Value for every records or group).

Related

Is it possible to suppress a group header based on various conditions in details?

I have report with a group 1 and group 2. For formatting purposes group 2 header and details are suppress and all information is presented in the group 2 footer. I have set up the report to suppress the group 2 footer if a certain condition is met, The means that sometimes the entire section under the group 1 header is blank and I want to suppress it.
Here is how it is set up
Group 1 - Employee
Group 2 - Client (suppressed)
Details (suppressed)
Client name field1 field 2 field 3 field 4
For fields 1-4 the are possible returns of "Draft", "Final" and null. I'm only looking for "Draft" and null values.
So how I've set up the group 2 footer is to just return the client name and a formula summing up the values of all four fields {#draft}
if {#divDraft} + {#convoDraft} + {#yearDraft} + {#rovDraft} >= 1 then "Draft"
else if {#divFinal} + {#convoFinal} + {#yearFinal} + {#rovFinal} >= 1 then "Final"
else " "
I then suppress the footer based upon {#draft} returning "final"
Is possible to suppress the group 1 header if every client in that group has either all four fields returned as null or at least one returned as draft?
I tried running a subreport and then placing that and a shared variable in the group 1 header but that didn't work right
WhilePrintingRecords;
Shared NumberVar totalSuppress;
Global NumberVar suppression;
suppression := Shared NumberVar totalSuppress;
The {#totalSuppress} formula in the shared report added the times at least one "draft" was returned with the number of times all four fields were null. I placed that in the footer of the subreport and then {#suppression} in the main report group header.
What I got was a pattern where the first group header was returned 0.00 where it had 4 results and 4.00 in the group footer. Then the next group had 4.00 in the group header where it had 1 result and 1.00 in the group footer. And the next one had 1.00 in the group header and so on.
I tried to do a formula to reset the variable with each group header. So I wrote
Global NumberVar suppression;
suppression := 0
But all that did was return 0.00's in the group header.
Any other ideas would be welcome.
RE: Tried new formula
if {sales_div.draft_pend_approv_Value} = "Draft" or {sales_div.draft_pend_approv_Value} = "Pending Approval"
or {convoSales_200.pending_approval_Value} = "Draft" or {rov_client.pend_draft_Value} = "Draft"
or {yearly_sales.draft_pend_Value} = "Draft") then 1
else if isnull({sales_div.draft_pend_approv_Value}) and
isnull({convoSales_200.pending_approval_Value}) and isnull({rov_client.pend_draft_Value})
and isnull({yearly_sales.draft_pend_Value})
then 1
else 0
If I understand correctly, you're trying to use the result of a Running Total Field to suppress a header - which won't work as the running total is only calculated in the footer.
You can try a different approach. Make a Formula Field which will go into your Details section. It should simply check if that row is the kind that you want to show, something like:
if (isnull({field1}) or isnull({field2}) or ... or {field1} = 'Draft' or {field2} = 'Draft' ...)
then 1 else 0
Then in the Group Header #1, in Section Expert, inside the Suppress formula put
sum({#check},{Employee})=0
where {#check} is that formula field and {Employee} is the field on which Group 1 is created

How to count number of grouped rows in the Crystal Report

I need to count and show number of rows of grouped data in the report. I already have number of rows of total data in Report Footer section (I used Count() function and that works fine), but I need to have total rows in the Group Footer section which shows number of rows of grouped data. The visible explanation of the problem is shown under.
Thanks.
----------------------------------------------------
Group 1
row 1---------------------------
row 2---------------------------
.
.
.
row N---------------------------
--- I need here number of rows!---------------------
----------------------------------------------------
Group 2
row 1---------------------------
row 2---------------------------
.
.
.
row M---------------------------
--- I need here number of rows!---------------------
----------------------------------------------------
Total Rows: M+N
Try the solution
Create a formula #reset. Place the formula in groupheader and supress
Shared Numbervar count;
count:=0
Now create one more formula # Increment and place in section where there are rows I have assumed it as detail section and supress.
Shared Numbervar count;
count:=count+1;
count;
Now create one more formula #Display. Place this formula in Group footer
Shared Numbervar count;
Shared Numbervar Count_Final;
Count_Final:=Count_Final+count;
count;
Now create one more formula #DisplayFinal and place in Report Footer
Shared Numbervar Count_Final;
Count_Final
This solution may help someone,
Create a Running Total:
Choose a field
Select distinct count as Type of summary
Choose your group name in Reset section
Now drag and drop the running total field in group footer.
Refer the image below
This solved my problem
Create new formula field
{IM_INV.QTY_ON_HND}-{IM_INV.QTY_ON_HND}+1
{Existing field} minus {exiting field} plus 1
This gave me a "1" next to each detail line in a field I called {NumberForCount}
Because it was made this way it showed up in running total field options
Then made a running total field like normal in the footer
Another way to try by using Summary
Right Click > Insert > Summary
Choose Field (I choose string
value)
Choose "Count" to Calculate This Summary Combo box
Choose Summary Location in Where would you like to show this total
Then OK

crosstab report how to calculate specific columns values and subtract from row total

am stuck at a point that in Crosstab report, i need to have sum of only two column's value and subtract the total by the value what should i do?
as in below,
Product 1 Product2 Product 3 Total
----------------------------------
Cust 1 4 5 2 11
Cust 2 5 9 7 19
I want to sum values of "Product 1","Product 3". then subtract from row total=> Total
LIKE
[4+2]-11=>TOtal.
and want to repeate this for each customer..
anyone please help me out.
I'm not sure when embedded summaries were introduced but I am pretty sure that your version of Crystal has this functionality. If not I apologize ahead of time. I have only been using this method for a few months now and it is quite confusing at first. At least to me but it has come in quite handy.....
I am making the following assumptions about your crosstab. Make name changes as you need to
row {yourtable.CustID}
Column {yourtable.product}
summarized field {yourtable.cost}
In the top left of your crosstab, right click go to advanced calculation and select calculated member
Select New and enter a description
For Type: Select Column
For insert Evaluation: Select After
Click edit insertion value and enter
CurrentColumnIndex=(GetNumColumns-2)//This will insert a column just before the total column
Click edit header formula and enter in quotes what you want to call the column
Select the content in Value Formulas then click Edit Value formula and number value
Save and close then exit the calculated member expert
Your crosstab should now have a new column
Right click the value go to Calculated member and select edit calculation formula
Enter this formula
(
GridValueAt (CurrentRowIndex,0 , 0) // Product 1 value
+
GridValueAt (CurrentRowIndex,2 , 0) // Product 2 value
)
-
GetTotalValueFor "yourtable.product")
NOTE: Geez it is hard to post on this site!
well after thinks long on it I've have done......
1st be clear that crystal report 10 is not offer following function
"CurrentRowIndex", "GridValueAt"
 
that's why above solution by "CoSpringsGuy" is not applicable.......
as we have two tables. 1 customer and 2nd for products and by both we generate crosstab with summarize field of product_sold (Qty) and 2 crosstab columns “Product.name”  and sub column product. Type
Now we want to sum value under the product.packing type =”Pilot”  of  product sold to each customer and subtract the sum-up from grand total of all products (product type “Normal” and “Pilot”)
For this problem 1st we have to work on formatting formula at crystal runtime and manipulate to “Display string” of summarize field
And then we will edit totals i.e very last column
1st edit summarize filed “display string” with the help of following code
Global CCust As String to keeping last customer for teli new customer name
Global Ccol As String ' tht is for keeping last column/product.packing type and teli with new col
Global Rndx as number ' this is for generating index of the row
Global totperx(22) as number ' is to hold the currnt value of cell and adding with previous value
' and i imagen that number of customers will less then 22 otherwise you can take unlimited array
Whileprintingrecords
if (CCust="") then
CCust=gridrowcolumnvalue("Table_Cust.Name")
Ccol=gridrowcolumnvalue("Viw_Prod.Packing")
Rndx=1
formula="new"
end if
if CCust<>gridrowcolumnvalue("Viw_Prod.Packing") then
formula="same"
Rndx=Rndx+1
else
formula="Newag"
end if
if Ccol<>gridrowcolumnvalue("Viw_Prod.Packing") then
Rndx=1
end if
if gridrowcolumnvalue("Viw_Prod.Packing")="Pilot" then
totperx(Rndx)=totperx(Rndx)+currentfieldvalue
end if
formula=totext(currentfieldvalue,0,"") ' despite of cstr function totext will change 45 to 45 while cstr changes 45 to 45.00
CCust=gridrowcolumnvalue("Table_Cust.Name")
Ccol=gridrowcolumnvalue("Viw_Prod.Packing")
now we will edit "Display String" of grand total column
Global my as number
Global totperx(22) as number
whileprintingrecords
if my<1 then
my=1
end if
formula=currentfieldvalue-totperx(my)
my=my+1

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.

How can I filter a report with duplicate fields in related records?

I have a report where I need to filter out records where there is a duplicate contract number within the same station but a different date. It is not considered a duplicate value becuase of the different date. I then need to summarize the costs and count the contracts but even if i suppress the "duplicate fields" it will summarize the value. I want to select the record with the most current date.
Station Trans-DT Cost Contract-No
8 5/11/2010 10 5008
8 5/12/2010 15 5008
9 5/11/2010 12 5012
9 5/15/2010 50 5012
Create a group on Contract-No.
Create a formula field to display most recent Trans-DT.
Something like: Maximum ({Trans-DT}, {Command.Contract-No})
Create your summary fields or running totals based on the newly created Contract-No group.
Edit:
To summarize costs and count contracts, you'll need a bit of trickery.
Add this (in a formula field) to the report header section:
// start the sum
// put in report header
WhilePrintingRecords;
Global NumberVar TotalCost := 0;
This goes in the report footer:
// final count
// put in report footer
WhilePrintingRecords;
Global NumberVar TotalCost;
TotalCost;
And place this in a formula field within your Contract-No or Station group:
WhilePrintingRecords;
Global NumberVar TotalCost;
if {Command.Trans-DT} = maximum({Command.Trans-DT}, {Command.Contract-No}) then
TotalCost := TotalCost + {Command.Cost}
else
TotalCost;
I'll leave the counting part to you. Good luck!