Summary or running total of array elements - crystal-reports

I am creating a invoice printing system using Crystal Reports XI, where I get item details and quantity from database but item rate is entering by the end use as a comma separated parameter field. I am able to show rate with their corresponding item. I also able to calculate the item-value. but I am not able to calculate the total of the item-value. I am sharing the formula which I am using.
For Serial Number #SL=>
numberVar numSlno = 0;
IF PREVIOUSISNULL({ICTRED.ITEMDESC}) THEN
numSlno := 1
ELSE
numSlno := numSlno + 1
For Unit Price #unitPrice=>
IF {?UnitPrice}<>"" THEN
ToNumber(Split({?UnitPrice},",")[INT({#SL})])
For Item-Value #ItemValue
{ItemTable.qnty}*{#unitPrice}
Now I am trying to get the summary of #ItemValue.
Thanks in advance.

I got the solution, I used three-formula trick for #ItemValue and its working.

Related

Summing a formula containing a running total in Crystal 10

I have searched on other questions similar to this but none seem to be in the same situation.
I have a series of transactions in which I am using a running total named TranNumber which resets on the change of the account number. When I sort by descending transaction date this running total gives me the most recent transaction as 1.
I also have another formula which contains a list of transaction codes and their position on a workflow (done using a select case formula).
I have tried to sum the following formula as well as variations such as using variables and passing data into a sub report and back to 'trick' the software into not seeing it as a running total, still to no avail as I can then not sum a variable.
if {#TranNumber} = 1 then
if {#ProcCode} startswith "1 - " then 1 else 0
Ultimately I want a count of accounts in each position on the workflow to then put into a graphical form.
If anyone has tried to do this successfully or can suggest a way to only bring back the most recent transactions for each account to avoid having to use the above method it would be greatly appreciated :)
Thanks in Advance
Resolved this issue by using the formula above and assigning to a variable and placing a counter formula in the details which worked like the below
shared numbervar x;
If {#TranNumber} = 1 then
if {#ProcCode} startswith "1 - " then x := x + 1
I then placed this formula in the details and then simply output the variable in the report footer which gave me the number I was looking for.

How to get the COUNT of rows in Crystal Report

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.

crystal report use Maximum as Sum condition problem

I met a problem with sum function:
the data have a datetime column and I want to get sum of who's datetime is max. And also there's anoher group condition.
So I do like:
Add formula maxDatetime: Maximum({datetime}, {groupcondition})
Add new formula for sum ValueToSum: if({datetime} = {#maxDatetime}) then value else 0
Sum the value, add new formula totalValue: Sum({#valueToSum}, {groupcondition})
The result is the sum can't be processed, it says: 'valueToSum can't be sumed'.
I think the causor may be using a maximum value as a condition in step 2. Because when use 1 = 1 to replace the condition, there's no problem.
Can anyone give some advice?
We usually solve such kind of problems by creating additional queries and linking them to main data. Because Crystal Reports does only two passes over data - record reading and aggregate calculation, it can't easily aggregate over already aggregated values.
Another possibility is to accumulate your 'totalvalue' into variable. Something like next may work (needs tweaking probably):
WhilePrintingRecords();
NumberVar totalvalue;
If ({datetime} = Maximum({datetime}, {groupcondition}))
then totalvalue:=totalvalue+value
else 0
This formula (which displays totalvalue) needs to placed into group footer:
WhilePrintingRecords();
NumberVar totalvalue
Somewhere in group header you need another one to reset totalvalue:
WhilePrintingRecords();
NumberVar totalvalue:=0

Conditional Running Total in Crystal Reports

Using VS 2008 Crystal Reports, I would like to do a running total on a formula that is calculated on a group change. When I click on add a running total, this formula does not appear in the Available Tables and Fields list.
This is the logic:
On Change Group of group
if CalculatedValue > 0 then
ReportRunningTotal1 += CalculatedValue
else
ReportRunningTotal2 += CalculatedValue
Can I specify a condition in a running total? If not, how else could I do this?
More info: I am doing a running total called GroupRunningTotal of the value of db field BillableHours. At change of group, I am comparing GroupRunningTotal to a db field for that group MaxHours, and I display a result of MaxHours - GroupRunningTotal at the group level.
Appropriate today - Think of it like the electoral college - the person who wins the election does not depend on total number of votes, but of number of votes in the electoral college.
I'm interpreting your question to mean that you want to add up all the negative values in one running total (RT_Neg) and all the positive values in another (RT_Pos). How about this:
Make the RT_Neg running total. Under Field to Summarize, sum your {Tbl1}.{Amount}. Under evaluate, enter "{Tbl1}.{Amount}<0" as your custom formula. Never reset.
Make the RT_Pos running total. Under Field to Summarize, sum your {Tbl1}.{Amount}. Under evaluate, enter "{Tbl1}.{Amount}>0" as your custom formula. Never reset.
Insert both running totals in the group footer (if you put them in the header, it may not sum properly)
Alternatively, you can:
Make a custom formula "If {Tbl1}.{Amount}<0 then {Tbl1}.{Amount} else 0" and make a running total based off that.
I think one of these 2 options will get you to your goal.
You most likely cannot use one RT field as condition for other RT field. You can use formulas, placed on group footer and evaluated 'whileprintingrecords()'; in these formulas you can assign/sum into some variables and display these variables at the end of report. About like next (generic idea only, you need initialization and display routines as well):
numbervar rtcurrent := sum({somefield}, {groupfield});
numbervar rtplus;
numbervar rtminus;
if (rtcurrent > 0)
then rtplus := rtplus + rtcurrent
else rtminus := rtminus + rtcurrent;

Is it possible to programmatically iterate through a table within a formula in crystal reports?

Is it possible to programmatically iterate through a table within a formula in crystal reports?
E.G. If I have a master table and a detail table can I iterate through the detail table e.g.
( psuedo code )
local numberVar Total := 0
While not EOF()
IF Type = "+"
Total = Total + Quantity
ELSE IF Type = "-"
Total = Total - Quantity
ENDIF
<Next Record>
End While
It is possible to use loops in a formula field to get the data that you need, but I have only really used them in complex string manipulation. If you really need to do this then you may be able to look into using subreports, but you'd need to put the subreport in the details section which is not really recommended because it is essentially like running a new report for each record that is pulled.
It sounds like what you are really looking for is a running total field. If you join the master and details tables together the report will pull all of the rows for both tables. Then you can group by "Type" and create a running total field that sums the "Quantity" field for each row and resets on the change of the group. I think it is a little different way of thinking than traditional programming. Hope this helps.