Cystal Report Accumulated Balance First Record Missing - crystal-reports

I have used the following formula in the UnboundNumber (Accumulated balance), but the blue circled field is missing and wrong coming:
If Next({SP_Aging;1.AHead}) = Previous ({SP_Aging;1.AHead}) Then
numberVar X := (X + {SP_Aging;1.Balance} )
Else
X := 0 +{SP_Aging;1.Balance}
;

Try:
// {#Accumulated Balance}
// declare variable; mark as `global` to be explicit (w/o this, the variable is `global`, but this makes it clearer)
Global Numbervar balance;
// if this is the first row, increment the balance; always test for NULL values first in CR
If PreviousIsNull({SP_Aging;1.AHead}) Then
balance := {SP_Aging;1.Balance}
// if the current row's AHead is the same as previous row's value, increment balance
Else If {SP_Aging;1.AHead} = Previous({SP_Aging;1.AHead}) Then
balance := balance + {SP_Aging;1.Balance}
// otherwise, reset
Else
balance := {SP_Aging;1.Balance}

Related

Repeat the value if belongs to same group

Possible outcomes of the formulaHi all,
I am seeking some help to repeat the field name within the same group as shown in the image. I have used the following formula to create Via:
shared numbervar counter;
If {Command.ACTIVITY}= 'Pick' and
(previousISNULL ({Command.PASSONBOARD}) or previous
({Command.PASSONBOARD})="")
and next ({Command.ACTIVITY})='Pick'
then (
counter := counter + 1;
"Via" + cstr(counter))
else ""
I would appreciate the help. Thanks

Crystal Reports 13 Standard Deviation with formula fields

I've been working on a report made by someone else which uses the StDev function. I thought it would be simple enough, but the data can contain multiple values for each record, so there are if statements used to determine which value to take from each record. I've exported a table to Excel which contains one value per record (the one that should be used in the StDev), and then calculated the SD there to provide a check.
The report and Excel are giving me very different values :(
So, I'm going back to the report and using some additional formula fields to calculate the SD longhand to act as a kind of deciding vote (fingers crossed it doesn't produce a third set of values...).
I've worked out the syntax errors, but am still getting a run-time error - "Division by zero" which then highlights the section of code indicated below...
My formula fields are:
{#StDevArrayPopulate} - in the details section
NumberVar Array varStDevArray;
NumberVar varStDevArrayCount;
varStDevArray [varStDevArrayCount] := {ValueToSummarise};
varStDevArrayCount := varStDevArrayCount + 1;
{#StDevArrayCalculate} - in the group footer
NumberVar Array varStDevArray;
NumberVar varCounter :=1;
NumberVar varMean := 0;
NumberVar varStDev := 0;
NumberVar varStDevArrayCount;
// START OF MEAN
// Sum of all of the values in the array
for varCounter:= 1 to varStDevArrayCount step 1 do
(
varMean := varMean + varStDevArray [varStDevArrayCount];
);
// Divide by the total number of values in the array
varMean := varMean / varStDevArrayCount; // !! This is the line that highlights after the error message !!
// END OF MEAN
// START OF STANDARD DEVIATION
// Subtract the mean from each value in the array and square the result
for varCounter := 1 to varStDevArrayCount step 1 do
(
varStDevArray[varStDevArrayCount] := (varStDevArray [varStDevArrayCount] - varMean) * (varStDevArray [varStDevArrayCount] - varMean);
);
// Sum of all of the values in the array
for varCounter:= 1 to varStDevArrayCount step 1 do
(
varStDev := varStDev + varStDevArray [varStDevArrayCount];
);
// Divide by the total number of values in the array
varStDev := varStDev / varStDevArrayCount;
// Square root of mean of differences
varStDev := Sqr(varStDev)
// END OF STANDARD DEVIATION
{#StDevArrayCalculate} - in the group footer
NumberVar varMean;
NumberVar varStDev;
"The mean is " & varMean & ", and the standard deviation is " & varStDev & "."
I've tried using a Running Total field but that was giving errors as it need to be count the first record before the Populate formula field ran. I've also tried adding a fourth field to the header, which initialises the varStDevArrayCount as 1.
Does anyone have any suggestions?
Looks like there are no detail records hence you are getting zero in array... I don't think initializing with 1 will make any difference instead make a small change like below and check.
if varStDevArrayCount=0
then
varMean :=varMean
else
varMean := varMean / varStDevArrayCount;
I would advice you to just check records in detail and then debug

Calculation of Previous field

New to CR and use CR v10 and SQL Server 2000.
For the first record i.e Beginning Balance , the calculation is sum(field) from the input date, which I have calculated in SP as BegDateSum
But for the rest of the records under a group, the calculation should be previous(balance)+IN+OUT
Sample has been given:
Date Doc Descrip IN OUT Balance
Group Header-------- Beginning Balance-------------- 50 <---- sum(field) from my inputdate
3/2/2012 A -1 0 49 <-- (50+(-1)+0)
4/2/2012 B -2 0 47 <-- (49+(-2)+0)
5/2/2012 C 0 3 50
6/2/2012 D -2 3 51
How do I achieve this?
I am not sure whether to use running total, in case I have to how to do it.
A running total field won't work in this case, they are designed to add up (or count, or average, etc) one field and give you the sub-totals automatically. But, we can do some custom functions that will give the results you need. Assuming that your initial 50 is a static value, you would set a variable to that amount, and then add the IN and OUT values as you go along (printing that result of that).
First, initialize the value in the report header with a formula like:
WhilePrintingRecords;
Global NumberVar Balance;
Balance := 50;
""; //print nothing on the screen
Then, the formula to calculate and show the new balance, in the bar where the data is:
WhilePrintingRecords;
Global NumberVar Balance;
Balance := Balance + {tableName.IN} + {tableName.OUT};
The last line both calculates the new value, and tells what the result of the formula should be.
If the "50" is calculated somehow, then that will have to be done before the formula that calculates the new balance. If it is based off of the first record read in, you'll want to use a formula that includes If PreviousIsNull({tableName.Balance}) Then ..., that is usually a good indicator of the first record in the data set (unless that field can be null).

Crystal Reports Formula Variable Passing

I am working on this report pulls all of our Projected Purchases grouped by Month displaying a sum (called "Monthly_Total" for the month as well as displays the Budget (called "Monthly_Budget" for the month. I also have a subreport that I use a shared currencyvar "Starting_Balance". This shared variable updates whenever the report is run.
I need to find a way to do the following calculation:
for the first month (in this case the report starts with March) it should be
"Starting_Balance" + "Monthly_Total") - "Monthly_Budget" = "New_Balance"
each subsequent Month would use the formula
("New_Balance" + "Monthly_Total") - "Monthly_Budget"
I can get it to work for the first group footer, but with then each month after that is referencing back to the "Starting_Balance" rather than the "New_Balance"
any ideas?
Try using a flag variable that says whether or not the first month has been reported yet. I originally though of using New_Balance as 0, but that could potentially happen naturally.
So, something like
Initializer in the report header:
WhilePrintingRecords;
Global BooleanVar First_Month_Done := false; // have we printed the first month?
""; // print nothing on screen
Monthly formula
WhilePrintingRecords; // Optional when using shared variables
Global BooleanVar First_Month_Done;
Global CurrencyVar New_Balance; //or whatever it is
Shared CurrencyVar Starting_Balance;
// Assuming "Monthly_Total" and "Monthly_Budget" are formulas, not variables
If First_Month_Done
Then New_Balance := New_Balance + {#Monthly_Total} - {#Monthly_Budget}
Else New_Balance := Starting_Balance + {#Monthly_Total} - {#Monthly_Budget};
First_Month_Done := true;
New_Balance

Crystal report dynamic formula name

Here is what I have. I have 15 unique formulas named Week1, Week2, ... Week15. I would like to be able to take a parameter name, MYCount, and use that to loop through the records and sum them. So if MyCount is equal to 3, the loop would sum Week1 + Week2 + Week3. I know how to create a loop, but I cannot figure out how to build the formula name dynamically. Here is what I have so far: (I am using Crystal Xi)
Whileprintingrecords;
local NumberVar i := {?MyCount}
For i := 1 To (MyCount-1) Do (
i = {#Week & "i"} + i
);
x
I think you may be over complicating. Why not just do:
Local numbervar x := 0;
If param > 0 then
X := x + week1;
If param > 1 then
X := x + week;
And so on...
X;
I don't exactly what you are trying to do, but you may want to consider another approach.
Create a formula that will segment a field based on a date field's week number:
//{#amount}
// adjust firstDayOfWeek and firstDayOfYear parameters to match your organization's
// definition of a week
If DatePart("ww", {table.dateField})<={?Week} Then
{table.amount}
Insert a summarized field on the formula field.
If you are using your #Weekn formula fields so that you can summarise by date across the page, then have you considered using Crystal's Crosstab functionality instead?