'how to get value of current row in Crystal Reports formula?

I have a formula in Crystal Reports that needs to sum only a certain number of values, but can't seem to figure out how to get the current value of a field for a current row. I only get the very last row value. I am using a loop like so:

Local Numbervar loop1:= Maximum ({ReportCommChecksSumm5Year;1.finalMonth});
local Numbervar i;
local Numbervar total:=0 ;
for  i:=1 to loop1 do (
   total:= total + tonumber({ReportCommChecksSumm5Year;1.Year1}) //this always returns the very last row value
);
total;

There are basically 12 rows of data from the database, but only the 12th row is accessible, so looping through the rows is impossible. Is there any way to process a current row? You can do this in SSRS, but I can't find any way of doing this in Crystal Reports.



Solution 1:[1]

Unlike in SSRS, in CR you can only access values from current report section (and additionally values of last and next row).

So it seems you could just sum up the required values, i.e. add an aggregate field "sum" into report footer or group footer.

Aggregating a field depending on others could by achieved by creating a new formula field that returns the value of the original field only when the conditions are met, and then aggregating on this new formula field.

For an example of the latter see this answer: Crystal Reports SUM formula help. Don't SUM values with specific IDs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1