Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal report; Combining rows of data into a single value

I have a data in rows like this for id 1

id1 a1

id1 b2

id1 c3

id1 d4

id1 e5

I like to combine it as "a1b2c3d4e5" into a single value for id1. Thanks in advance.

like image 480
Helen Avatar asked Aug 24 '10 15:08

Helen


People also ask

How do you concatenate two columns in Crystal report formula?

You will need to create a FORMULA to concatenate these strings. In the Field Explorer , right click the Formula Fields and select New. It will prompt you for a Formula Name. Enter the name of your choice, and hit enter.


1 Answers

One approach is the "3 Formula" method. You set up an initialising formula in each header, with the evaluation time directive "WhilePrintingRecords". This approach was the only one available for doing running totals in the "good ol' days" before RunningTotal objects were available.
For example:
In the Group Header :- Have a Formula @InitiliseRT

WhilePrintingRecords;
StringVar ConcatenatedID;
If Not InRepeatedGroupHeader Then
    ConcatenatedID := "";

In the Details Section :- Have a Formula @UpdateRT

WhilePrintingRecords;
StringVar ConcatenatedID := ConcatenatedID + id1;

Finally, in the Group Footer you can see the result :- Formula @ShowRT

WhilePrintingRecords;
StringVar ConcatenatedID;

This should give you your final string of "a1b2c3d4e5".

If you need to, you can add extra formulas for extra groups, one variable for each group (e.g. ConcatenatedIDGroup1, ConcatenatedIDGroup2). The key is to always get the name right between the groups, and to initialise the variable in the group header.
There are limitations to the use of these formulas. The built in summary functions (Sum, Max, Count, ...) or RunningTotals cannot use them, and you cannot group on them.

like image 128
Anthony K Avatar answered Sep 21 '22 23:09

Anthony K