Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Creating a Dynamic Array on the Fly Post Reply Post New Topic
Author Message
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Topic: Creating a Dynamic Array on the Fly
    Posted: 27 May 2009 at 10:45am
Hi All,
I have what might be a unique situation here.  I have a report that contains numbers for a 12 month period (not necessarily from Jan to Dec) and is grouped by county.  The starting month depends on what the user has entered as a date parameter (If the date entered is 5/2009, the first month would be 06/2008).  It there a way to create a 12 bucket array so I can get a grand total of each month for each county group?  Here's an example of what my report looks like:
 
County 1
06/2008            4
07/2008            0
08/2008            1
 
County 2
06/2008            8
08/2008            1
09/2008            1
 
So my grand total for 06/2008 would be 12
                             for 07/2008 would be   0
                             for 08/2008 would be   2
                             for 09/2008 would be   1
 
Thanks in advance for any assistance in this!
Frank
Frank
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 May 2009 at 11:58am

I think the easisest solution would be to use a crosstab in your report footer.

You can suppress all of the lines if you do not want it to appear as a "table".
Insert the crosstab.
Do not set any Column fields.
Use the Date field as a Row. Set the group option on it to "for each month".
Insert the summarized field as a count (or a sum of that is what you are using here) as whatever field you are using for your counting above (per country).
Go to Summarized Style tab and select format grid lines and select the items you do not want to appear and uncheck the "draw" check box to remove the grid lines.
 


Edited by DBlank - 27 May 2009 at 12:06pm
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 28 May 2009 at 7:14am
DBlanks answer is probably best, I haven't used cross tabs in Crystal, but if you don't want to use cross tabs...and I would give them a try...or they don't work for you, you can always try...shared variables
 
You could create an array and increment it (I haven't used arrays, but this would seem to be a perfect example for me to learn), but without arrays you would have your 12 shared variables.
shared numbervar month1;
shared numbervar month2; etc
 
since this is a report summary type situation, you don't need to reset them to 0, you just need to increment and display.
 
Incrementing would be something like:
shared numbervar month1;
shared numbervar month2; etc
 
//compare your dates, like you did for the report and add the numbers
//if the value was for month2 the addition would look like:
month2 := month2 + {table.countField};
 
the display formula would be very similar but would be just 1 of the variables.  The one for month2 would look like;
shared numbervar month2
 
Hope this helps.  It is more of a framework then exact codes, but should get you started down the path...if you choose not use crosstabs.
 
IP IP Logged
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Posted: 01 Jun 2009 at 1:41pm

DBlank,

I inserted the crosstab and the date field as a row.  That part is working fine.  But the total amount for each mm/yyyy is the amount of the last occurrence and not a grand total.  It's not adding them up. 

When you say "Insert the summerized field as a count" do you mean to create a new totals field?  I tried moving the line total field but that's when I get the last occurrence, which now that I think of it makes sense. 
 
When I use the "Insert Summary" feature I just get a single grand total.
 
Thanks.
Frank
Frank
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 01 Jun 2009 at 2:32pm

All depends on your data. In your example above you have:

County 1
06/2008            4
07/2008            0
08/2008            1
Are these red numbers a count of fields that are suppressed or just a number value in a column on this row?
is your raw data like
County    Date         NUmber field
1             6-08              4
or
County    Date         Other field for row counting
1             6-08              A
1             6-08              B
1             6-08              C
1             6-08              D
If they are counts of a field on rows (sample 2), put that field in your crosstab as the field to summarize.  Click on the Change Summary and put it as a Count.
If it is a number value (example 1), put that field in your crosstab as the field to summarize. Click on the Change summary and set it to a SUM.
 
Make sure this is in your report footer (or header), not a group footer.
IP IP Logged
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Posted: 02 Jun 2009 at 9:23am
The red numbers are a count (sample 2) and actually a running total field.  When I put this running total field into the crosstab in the "Insert Summarized Field Here" location, I do not get the option "Change Summary" upon right-clicking it in order to set it to "Count". 
 
Do I need to use a different type of field instead of a running total field?  And I am using the same running total field that being displayed and reset for each mm/yyyy line. 
 
Thanks for your help on this issue.
Frank
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Jun 2009 at 9:52am
Gotcha.
In your RT you selected a field that you are using to count.
Use that same field (not the actual RT but the "other field to get the count" ) in the Crosstab as the field to summarize. Set it as a Count.
 
When trying to reuse the reports Running Total (RT) it is going to calculate based on the grouping you did in the report (first by County then by Month). You want a summary that does not use the the double grouping,  only the single grouping (month data without splitting by county).
 
The only issue with this is if your RT is using a special formula for the evaulate section. If no special evaluation formula is being done this will work fine.
 
Make sense?


Edited by DBlank - 02 Jun 2009 at 9:53am
IP IP Logged
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Posted: 02 Jun 2009 at 2:01pm
You are a genius!  It's working perfectly.  I can't thank you enough.
 
Thanks!  Frank
Frank
IP IP Logged
redcolor
Newbie
Newbie
Avatar

Joined: 14 Mar 2011
Location: Netherlands
Online Status: Offline
Posts: 3
Quote redcolor Replybullet Posted: 15 Jul 2011 at 11:08pm
Hi Frank,
I have a similar issue. I have to get database info from the first month of the year (parameter date) till the month of the date (parameter date).
 
Could you tell me how to create this 12 bucket array?
 
Thanks in advance,
 
redcolor
 
redcolor
IP IP Logged
Frank in VA
Groupie
Groupie
Avatar

Joined: 15 Nov 2007
Location: United States
Online Status: Offline
Posts: 46
Quote Frank in VA Replybullet Posted: 20 Jul 2011 at 4:41am
Hi redcolor,
 
Sorry for not replying sooner, it's been really busy here. 
 
I did just what DBlank mentioned above.  I inserted a Cross-Tab to the Report Footer.  In the top-left cell I added my date.  To the left of that cell I added counts of the data fields I was adding up.  Then the bottom row I just created counts of the same fields but just didn't reset them when the group changed. 
 
Hope this helps.  I tried to send an image along to give you a visual but I couldn't quickly figure out how to attachan image!
 
Thanks.
Frank
Frank
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.031 seconds.