Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Grouping by one field in multiple records Post Reply Post New Topic
Author Message
SNelson
Newbie
Newbie
Avatar

Joined: 20 Jan 2017
Online Status: Offline
Posts: 13
Quote SNelson Replybullet Topic: Grouping by one field in multiple records
    Posted: 24 Jan 2017 at 4:13am
Is there a way to group clients, with multiple rows, according to an item in one field but based on a value in another field?

Example - need to group clients according to favorite item but keep all rows for client together and in original order. Favorite item may not be listed first.

How data appears:
ID     client     item     color     favorite
1     SMITH     FUTON     W     Y
1     SMITH     COUCH     B     N
1     SMITH     COUCH     B     N
2     JONES     CHAIR     R     N
2     JONES     COUCH     B     Y
2     JONES     COUCH     B     N
2     JONES     COUCH     B     N
2     JONES     FUTON     W     N
3     JOHNSON     CHAIR     R     Y
3     JOHNSON     COUCH     B     N
4     HOWARD     CHAIR     R     N
4     HOWARD     COUCH     B     Y

How need it to appear:                    
ID     name     item     color     favorite
COUCH                    
2     JONES     CHAIR     R     N
2     JONES     COUCH     B     Y
2     JONES     COUCH     B     N
2     JONES     COUCH     B     N
2     JONES     FUTON     W     N
4     HOWARD     CHAIR     R     N
4     HOWARD     COUCH     B     Y
FUTON                    
1     SMITH     FUTON     W     Y
1     SMITH     COUCH     B     N
1     SMITH     COUCH     B     N
CHAIR                    
3     JOHNSON     CHAIR     R     Y
3     JOHNSON     COUCH     B     N

Thanks for any help!

Edited by SNelson - 24 Jan 2017 at 5:19am
SNelson
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Jan 2017 at 8:57am
Possibly, but this might get a bit complicated. Do all clients have a favorite item?

-Dell
IP IP Logged
SNelson
Newbie
Newbie
Avatar

Joined: 20 Jan 2017
Online Status: Offline
Posts: 13
Quote SNelson Replybullet Posted: 24 Jan 2017 at 10:32am
Yes, all have a favorite item. Some clients just have one row, which is the favorite.

Stephanie
SNelson
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Jan 2017 at 11:21am
Cool, that makes it easier. What are the names of the tables that provide this data and how are they joined?

-Dell
IP IP Logged
SNelson
Newbie
Newbie
Avatar

Joined: 20 Jan 2017
Online Status: Offline
Posts: 13
Quote SNelson Replybullet Posted: 25 Jan 2017 at 4:15am
You're right - this gets complicated!
There are 5 views that are joined (inner) by ID. View1 links to view2, view 2 to 3 and onward through view 5.
There are two additional links that join the views and follow the same progression, one begins at view2 and the next at view3. These fields are not used in the example above but are used to sort and keep the records in order by ID (sort1 & sort2):
ID     client     item     color     fav     sort1     sort2
1     SMITH     FUTON     W     Y     1     1
1     SMITH     COUCH     B     N     2     1
1     SMITH     COUCH     B     N     2     2
2     JONES     CHAIR     R     N     1     1
2     JONES     COUCH     B     Y     2     1
2     JONES     COUCH     B     N     2     2
2     JONES     COUCH     B     N     2     3
2     JONES     FUTON     W     N     3     1
3     JOHNSON     CHAIR     R     Y     1     1
3     JOHNSON     COUCH     B     N     2     1
4     HOWARD     CHAIR     R     N     1     1
4     HOWARD     COUCH     B     Y     2     1


SNelson
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 25 Jan 2017 at 4:35am
Ok, you'll need to use two copies of the view that has the Favorite information. When you add a second copy of a table or view in the Database Expert, Crystal will throw a warning saying that it already exists in the report and asking if you want to add it with an "Alias". Then it will add the second copy with "_1" at the end of the name.

For this example, I'm going to use the names ViewA and ViewA_1. In this case we'll consider ViewA to have the favorite record and ViewA_1 to have all of the records.

1. If the view that has the item information is separate from the view that has the favorite information, link FROM the view with the item info TO ViewA.

2. Link from ViewA to ViewA_1 on the ID field.

3. Group by the ViewA.Item then Sort by Sort1 and Sort2 - if that info is in ViewA, make sure you use the fields from ViewA_1 instead of ViewA.

4. Put ViewA.Item in the group header section.

5. Put the detail information, using ViewA_1 in the details section.

6. In the Select Expert, add this filter:

    {ViewA.FAV} = 'Y'

This should get you close to what you're looking for.

-Dell
IP IP Logged
SNelson
Newbie
Newbie
Avatar

Joined: 20 Jan 2017
Online Status: Offline
Posts: 13
Quote SNelson Replybullet Posted: 25 Jan 2017 at 11:20am
Thank you - I will try copying the view and including the links! Looking forwarding to trying it.
SNelson
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 26 Jan 2017 at 3:40am
You don't need two copies in the database, just in the report.

-Dell
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.047 seconds.