Okay, here are two solutions. The first one will show columns 1 to 5 with remaining columns summarized in an "Others" column. The second solution shows how to create a crosstab that "wraps" after a certain number of columns.
Solution 1:
Let's call your user defined column field {table.udf}. For this solution to work properly, you MUST first sort your report on {table.udf} (report->sort records). Then create a formula {@colbyorder}:
numbervar col;
stringvar x;
if instr(x,{table.udf}) = 0 then
(x := x + {table.udf};
col := col + 1);
if col in 1 to 5 then
totext(col,0,"") + " - " + {table.udf} else
"6 - Others"
Insert a crosstab and use {@colbyorder} as your column field. Use whatever group and summary fields you like. Place the crosstab in the report header or footer. If you want to identify what results are included in "Others", then create two formulas:
//{@detOthers} to be placed in the details section and suppressed:
numbervar col;
stringvar y;
if col > 4 and
instr(y,{table.udf}) = 0 then
y := y + {table.udf} + ", ";
//{@displOthers} to be placed in the report footer:
whileprintingrecords;
stringvar y;
left(y,len

-2);
Solution 2:
First, go to report->sort records and sort your report by {table.udf}. Then create a formula {@grp}:
numbervar col;
stringvar x;
if instr(x,{table.udf}) = 0 then
(x := x + {table.udf};
col := col + 1);
if col in 1 to 6 then 1 else
if col in 7 to 12 then 2 else
if col > 12 then 3 //add other intervals as necessary
Then insert a group on {@grp}.
Next, insert a subreport. In the subreport, go to report->sort records, and add {table.udf} as the sort field. Then, still in the subreport, create a crosstab that uses {table.udf} as the column field, and then add your row and summary fields. Go to the customize style tab and check "Suppress Row Totals", since you probably are not interested in the subtotals for these columns.
Place the crosstab in the subreport report footer. Copy the {@grp} formula from the main report into a new formula within the subreport, add this field to the details section. Suppress all sections of the subreport except the subreport footer.
Link the subreport to the main report by linking the {@grp} formulas in the main report and subreport. Place the subreport in the main report group header or footer.
To show a total across all columns, you can do one of two things. In the main report, you can insert a crosstab into the report footer that uses only your row and summary fields.
Or, if you want the total next to the last group column, you can insert an unlinked subreport, again using just the row and summary fields, and place this next to your first crosstab (this assumes you have allowed room) in the group section. Then while in preview, select this new crosstab->format subreport->common->suppress->x+2 and enter:
not(nextisnull({@grp}))
This will suppress the total crosstab in all but the last group. If there will be a constant number of columns in the last group instance, you can format the total crosstab to suppress each row label and also, in the customize style tab->show grid lines->select the lines around the row labels and uncheck "draw" so that the grid only displays around the total column. Then you can align this to appear to be the last column in that group.
-LB