vrijdag 9 mei 2014

Crystal Reports: Displaying Values from a Column in a Single Text Field

The other day I discussed the solution for this problem in Report Builder / Reporting Services. A couple of days later I got the same question for Crystal Reports. Somebody wanted his report to look like this:

In the example I am showing Customers and Order numbers from the Noordenwind database, the Dutch equivalent to the Northwind database.

How can we get this result? I created a report grouped on Klanten.Bedrijf. In the group header I put the formula field orderreset:

shared stringvar ordercollect:=""; 

In the detail section I put the formula field ordercollect:

shared stringvar ordercollect;
ordercollect:=ordercollect & totext({Orders.Order-id},"00000") & ", ";

In the group footer I put first of all the group name field Klanten.Bedrijf and next to it the formula field orderprint:

shared stringvar ordercollect;

Finally, I suppressed the details and the group header section ending up with the result on the picture.

Of course we could improve the formula fields in order to remove duplicates for instance. Then, we need three more complex formulas like

shared stringvar array productcollect;
shared numbervar i:=0;
redim productcollect[1];
shared stringvar array productcollect;
shared numbervar i;
if not({Producten.Productnaam} in productcollect) then
i := i + 1;
redim preserve productcollect[i];
productcollect[i] := {Producten.Productnaam};

and productprint:
shared stringvar array productcollect;
join(productcollect,", ")

The result:

You can download the files klantenorders.rpt and klantenproducten.rpt through


Een reactie plaatsen