Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Grouping question Post Reply Post New Topic
Author Message
ontu78
Newbie
Newbie


Joined: 15 Aug 2010
Location: United States
Online Status: Offline
Posts: 4
Quote ontu78 Replybullet Topic: Grouping question
     Posted: 15 Aug 2010 at 8:43pm
Hello,
 
We are currently in the process of designing a report  from a table that has the following sample data
 
Bus Unit      Affiliate         Amount
-----------     ----------       ------------
 
  01               02                2500
  01               03                2330
  01               04                  40
  02               01               -2500
  02               03                 -223
  03               01                -400
  03               02                 540
  04               03                 650
  04               06                  100
 
and so on....
 
In other words, the BU/Affiliate combinations do not follow any specific pattern.
 
We are tyring to present the data in the following way in the report
 
Bus Unit      Affiliate            Total
----------      ----------           --------
 
 01               02                  2500
 02               01                 -2500
                                        --------
                    Subtotal:             0
 
01               03                   2300
03               01                    -400
                                        --------
                    Subtotal:       1900
 
01               04                   40
04               01                     0 ( because combination not defined in table)
                                        ---------
                     Subtotal:       40
 
02              01
01              02 ..............These 2 rows should not be in the report, as they are already in the report....
 
 
02              03                     -240
03              02                      540
                                     -     -----
                   Subtotal:          300
 
and so on.............
 
 
In other words, the opposite Bus Unit/Affiliate combinations rows should be following each other.
 
If someone could provide suggestions about ways to accomplish this, we'd be very thankful.
 
Thanks again
 
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 16 Aug 2010 at 4:30am
the grouping is working as it should. Rather than try to craft a way around this, I would look to suppress the section...much easier.
 
I would create a shared stringvar that would track if a BU/Aff has been displayed...something like:
 
in group footer:
shared stringvar displayed;
 
if instr(displayed, "|"+{table.bu}+"|")= 0 then
  displayed = "|" + {table.bu} + "|"
 
in the group footer suppression (section expert)
shared stringvar displayed;
instr(displayed, "|"+{table.bu}+"|") > 0
 
 
HTH
IP IP Logged
ontu78
Newbie
Newbie


Joined: 15 Aug 2010
Location: United States
Online Status: Offline
Posts: 4
Quote ontu78 Replybullet Posted: 16 Aug 2010 at 6:40am

Thanks for your suggestion. I'm fairly new in designing Crystal reports, and am somewhat confused by your advice. I've grouped by BU and then by Aff, and added the Total field in the Aff group footer. But this does not allow us to display the opposite BU/Aff rows...e.g.

BU      Aff          Total

01      02          1230

02     01            -230

      Subtotal     1000

 
01     03             1000
03     01              -200
 
       Subtotal      800
 
Can you please elaborate? Thanks
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 Aug 2010 at 3:23am
Sorry, I thought that you already had that figured out.
 
what you need is a way to 'join' the reversed records to the 'regular' records.
 
I am not sure of how one would go about this.  I would modify the stored procedure that is gathering the data and add a column that I can use, which in my mind is the simplest solution. The problem is, most people do not seem to use stored procedures to create their reports.
 
Sorry I can't be more helpful.
 
IP IP Logged
ontu78
Newbie
Newbie


Joined: 15 Aug 2010
Location: United States
Online Status: Offline
Posts: 4
Quote ontu78 Replybullet Posted: 17 Aug 2010 at 3:39am
Thanks...to avoide duplicate groups, you suggested using two formula..one on group footer, and the other in group footer suppression ( via section expert). I understood how to add the formula for the latter. Can you please elaborate on how to use the first formula?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 19 Aug 2010 at 3:08am
what I was thinking was to create a string that would track which BU/Aff have been displayed, and if they had already been displayed, to hide them.
 
As to how you would accomplish this, create a formula, enter the code and then place the formula on the report in the section desired.
 
HTH
IP IP Logged
ontu78
Newbie
Newbie


Joined: 15 Aug 2010
Location: United States
Online Status: Offline
Posts: 4
Quote ontu78 Replybullet Posted: 29 Aug 2010 at 6:23pm
Hello again,
 
Here is what I did:

- Used the following SQL:

select BU as "Entity", 'A' as "Type",Affiliate as "Entity2", Amount
from Mytable
union
select Affiliate as "Entity", 'B' as "Type", BU as "Entity2", Amount
from Mytable

This results in the following sample data:

Entity    Type     Entity2   BU     Affiliate   Amount
------    ----     -------   ---    ---------   ------

GL01        A       GL58     GL01      GL58      -500
GL01        B       GL58     GL58      GL01       500
GL58        A       GL01     GL58      GL01       500
GL58        B       GL01     GL01      GL58      -500

In the report, when I group by Entity, and then by Entity2, I'm getting duplicate rows in the following manner:


Group by GL01
  Group by GL58

          BU        Affiliate       Amount
          --        ----------      -------

          GL01        GL58           -500
          GL58        GL01            500
                                     -----
                           TOTAL:      0



Group by GL58
   Group by GL01

          BU        Affiliate       Amount
          --        ----------      -------

          GL58        GL01            500
          GL01        GL58           -500
                                     -----
                           TOTAL:      0



The "Group by GL01,then by GL58" is exactly what I want. However, this also creates the "Group by GL58,then by GL01"
rows, which are basically duplicate rows, and I dont want them to be displayed. Is there a way to achieve this?

Thanks again
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 31 Aug 2010 at 3:41am
ok, now that you have solved the grouping issue, my solution can now apply.  In the group footer for Entity2 you can put the formula that looks like:
 
shared stringvar displayed;
if instr(displayed, "|" + {table.Entity2} + "|") = 0 then
  displayed := displayed + "|" + {table.Entity2} + "|";
""  //hides displayed from being shown
 
 
in the section expert for all the sections that you want to hide (which looks like 2 group headers a group footer and the details section) in the x-1 button for suppress add a formula like:
 
instr(displayed, "|" + {table.Entity} + "|")
 
 
the idea is you print the first sections, then keep track that you have displayed.  When you encounter the second value, you hide it from being displayed.
 
The big caveat is that the aggregate function (COUNT, SUM, AVG) will not give the correct values as they operate on the complete dataset, not just what is displayed.
 
HTH
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