Here is a solution that seems to work with fabricated data. First, insert a group on ID and then sort your records by the gift year in ascending order. In the following formulas I'm using {@year} (number datatype) to represent your gift year. Create the following formulas (Note that new formulas are preceded by //{@Name}-otherwise you are seeing the same (long) formula):
//{@reset} to be placed in the ID group header:
whileprintingrecords;
stringvar x := "";
stringvar y := "";
//{@accum} to be placed in the detail section:
whileprintingrecords;
stringvar x;
numbervar i := 0;
stringvar y;
if instr(x,totext({@year},"0000")) = 0 then
x := x + totext({@year},"0000")+", ";
stringvar array z := split (x,", ");
numbervar j := ubound(z);
for i := 1 to j do(
redim preserve z[j+1];
if
(
(
i = 1 and
val(z) = val(z[i+1])-1
)
or
(
i > 1 and
val(z) <> val(z[i-1])+1 and
val(z) = val(z[i+1])-1
)
) and
instr(y, z) = 0 then
y := y + z + (if len(z) <> 0 then "-") else
if
val(z) < val(z[i+1])-1 and
instr(y, z) = 0 then
y := y + z + ", " else
if z = z[ubound(z)-2] and
{table.ID} <> next({table.ID}) and
instr(y,z) = 0 then
y := y + z else
y := y
);
y;
//{@displaymostrecentstreak} to be placed in the ID group footer:
whileprintingrecords;
stringvar y;
stringvar array k;
if instr(y,", ") > 0 then
k := split(y,", ") else
k := y;
numbervar b := 0;
numbervar c := ubound(k);
redim preserve k[c];
stringvar array m := "";
numbervar g := 0;
for b := 1 to c do(
if instr(k, "-") <> 0 then (
g := g + 1;
redim preserve m[g];
m[g] := k)
);
if g > 0 then
m[g] else "";
//{@accumstreaklength} to be placed in the ID group footer (and suppressed):
evaluateafter({@display});
whileprintingrecords;
stringvar array m;
numbervar g;
numbervar h := 0;
numbervar strk0;
numbervar strk2;
numbervar strk3;
numbervar strk4;
numbervar strk5;
numbervar strk6;
if g > 0 then
h := val(split(m[g],"-")[2])- val(split(m[g],"-")[1])+1;
if h = 0 then
strk0 := strk0 + 1;
if h = 2 then
strk2 := strk2 + 1;
if h = 3 then
strk3 := strk3 + 1;
if h = 4 then
strk4 := strk4 + 1;
if h = 5 then
strk5 := strk5 + 1;
if h = 6 then
strk6 := strk6 + 1;
//{@displaystreaklength} to be placed in the report footer:
whileprintingrecords;
numbervar strk0;
numbervar strk1;
numbervar strk2;
numbervar strk3;
numbervar strk4;
numbervar strk5;
numbervar strk6;
"Frequency of Donors by Years of Consecutive Giving: "+chr(13)+
"None: "+ space(18-len(totext(strk0,0,""))) + totext(strk0,0,"")+chr(13)+
"2 Years: "+space(15-len(totext(strk2,0,"")))+totext(strk2,0,"")+chr(13)+
"3 Years: "+space(15-len(totext(strk3,0,"")))+totext(strk3,0,"")+chr(13)+
"4 Years: "+space(15-len(totext(strk4,0,"")))+totext(strk4,0,"")+chr(13)+
"5 Years: "+space(15-len(totext(strk5,0,"")))+totext(strk5,0,"")+chr(13)+
"6 Years: "+space(15-len(totext(strk6,0,"")))+totext(strk6,0,"")
You must right click on this last formula->format field->common->check "Can grow". You should also go to the font tab->font and select a non-proportional font like Courier New or Lucida Sans Typewriter, so that the spacing is appropriate.
-LB