Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: grouping on partial data found in field Post Reply Post New Topic
Author Message
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Topic: grouping on partial data found in field
     Posted: 14 Feb 2012 at 10:33am
Field1
contains only a single word, each Field is UNIQUE

Field2
can be Null
can contain multiple words, one of which will be found in Field1 same row and the other which must be found in Field1 in any row

Example
Field1.......Field2
Apple........Apple Banana
Orange.....Orange Cherry Peach
Grape.......<NULL>
Banana.....Apple Banana
Cherry.......Cherry Orange Peach
Peach.......Cherry Peach Orange

I need to group on Field2
The “Apple Banana” group is easy to group because the data is uniform
But it not always is uniform.
I need the “Orange Cherry Peach” and “Cherry Orange Peach” and “Cherry Peach Orange” to be recognized as a group.
If Field1 is found anywhere in Field2 it is grouped with any other Field2 also containing the information in Field1

NEVER will there be a Field2 containing Orange and not also containing Cherry and Peach

(Additionally, those Field1 items where Field2 is Null will not be consolidated in a NULL group but will each be considered a separate group.)


Is this even possible?

IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 14 Feb 2012 at 10:27pm
I think I would write a formula to manipulate all the Cherry/Orange/Peach strings into the same order.
You could use Split and Join, or Instr and Mid or Left or Right;  there are many ways to play with strings.
Then you could make a Field2 formula which is either
       Field1 if Field2 is Null
       or  'Apple Banana',
       or the new formula above.
And group on that.
 
IP IP Logged
carstowal
Groupie
Groupie


Joined: 31 Jul 2008
Online Status: Offline
Posts: 80
Quote carstowal Replybullet Posted: 15 Feb 2012 at 3:52am
Came up with this to alphabetize the text in Field2:

If ISNULL({Field2}) then {Field1} else

(StringVar Parts:={Field2};
stringvar array sort;
numbervar loop1;
numbervar loop2;
stringvar temp;
sort:=split(Parts, " ");
for loop2:=1 to ubound(sort)-1 do(
for loop1:=1 to ubound(sort)-loop2 do(
if sort[loop1] > sort[loop1+1] then
(temp := sort[loop1];
sort[loop1] := sort[loop1+1];
sort[loop1+1] := temp)));
Join(sort," ")  )

Found the "Ripple Sort" code on crystalkeen

IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum