Joined: 01 May 2008
Location: United States
Online Status: Offline
Posts: 6
Topic: Counting distinct occurances within a group Posted: 08 May 2008 at 6:15am
Hello,
I've got a problem here and I don't know if there is even a solution. I've tried using Global variables and Running Total Fields and neither are working for me.
Basically I have this
-- Group Header (Fund) --
-- Group Header (Bank) --
-- Group Header (Account) --
-- Details --
-- Group Footer (Account) --
-- Group Footer (Bank) --
-- Group Footer (Fund) --
My report shows a transaction history for a list of funds. Each fund can have multiple banks, and each bank can have multiple accounts.
Let's concentrate on the Group Footer for Account. I want to suppress this footer if the fund has only one Bank, but show the footer if the Fund has multiple banks.
The problem here is I need to know the count of all the fund's banks before I ever start printing footers.
--
Running Total fields aren't working here, because like the name suggest they run with the total, so each footer I go to print has only the bank count up to that point. I've not found a way to get the count of all the banks.
Global variables seem like the way to go, but I run into a timing issue. I need to know the count of all the banks before I print the first footer. That puts me at having to count the banks WhileReadingRecords but I have no place to store the result to be used WhilePrintingRecords. If the report has multiple funds, I'll start to overwrite the result in my global variable.
I hope I've made myself clear. Any help would most certainly be appreciated!
Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Posted: 08 May 2008 at 11:43am
You are on the right track, but I'm still a bit confused and can't give you a complete answer. So here are my thoughts and you can run with it and report back if it does/doesn't work.
Yes, you need to use Global variables to do this b/c it's too complex for a simple running total. Re the problem you are having keeping track of the number of banks and funds, I would also use the PreviousRecord(fieldname) function to determine if the current record is different from the previous record. That way you will know when the bank name changes. Then you can increment a bank counter which only increases for each new bank. In fact, it might be easier to put this counter in the group header sections since they only change upon a new group being printed (assuming the group header doesn't get reprinted at the top of each new page). So, hopefully this will get you in the right direction for knowing how many banks are in each fund and printing the footer at the apprpriate time.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
Joined: 01 May 2008
Location: United States
Online Status: Offline
Posts: 6
Posted: 08 May 2008 at 12:09pm
Hi Brian, thanks for the reply and a great book,
I understand exactly what you are saying in your reply, I even have tried to implement something like that to keep a running total of the banks.
Here's where it breaks down for me, if I was counting banks and wanted to suppress the bank footer, this would work great. However, I trying to suppress the Account Number footer, based on the count of banks. Recall that the account number group is grouped within the Bank.
Bear with me as I try to highlight my problem through what Crystal Reports is doing WhilePrintingRecords
Print Fund Header
Print Bank Header (Increment @BankCounter)
Account Header
Transaction
Transaction
Account Footer (Suppress? I need to know the TOTAL bank count at this point, even though I haven't iterated through all the data to have a total count yet.)
Once I figured out there was no getting past this WhilePrintingRecords, I thought, "Ok, I'll just count the banks WhileReadingRecords". This works great if there is only one Fund, but as soon as I show a report with multiple funds, the BankCounter is only going to represent the last fund shown on the report.
I don't see a way past this, unless it's possible to update/store a value WhileReadingRecords that I can later retrieve WhilePrintingRecords. I would need to store the count of banks for a particular fund.
Hope this makes more sense, and thanks for any help you might offer!
--Michael
Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Posted: 09 May 2008 at 5:12am
There is a way around it. Store your bank counts in an array, one for each fund. This will get tricky, as you have to keep track of which fund goes into which array element (obviously, it would be much easier if Crystal supported multi-dimensional arrays).
So, in extremely rough terms (where WRR indicates WhileReadingRecords and WPR indicates WhilePrintingRecords)...
Fund Header WRR increment FundReadCount ReDim Preserve BankArray to have size = FundReadCount WPR increment FundPrintCount Bank Header WRR increment BankCount Account Footer WPR suppress based on BankArray value of FundPrintCount element Fund Footer WRR store BankCount in BankArray of FundReadCount element re-set BankCount to 0
Hopefully you understood that well enough to work out the details...
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