Author |
Message |
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|
Topic: Loop Posted: 27 Mar 2012 at 11:20pm |
Hi all,
I am currently working on a report, showing the number of new invoices added to the system. i want to show this on client level. I created a formula saying:
DISTINCTCount ({client.client_id}, {client.client_name}).
The cases are loaded on mass actions. The dates of these actions can change, there are days that this is always loaded.
I want to show a count of the unique client id's. This looked fine at first. But when we started testing this, the numbers didn't at up. When I ran the reports on the dates the cases were loaded, they wer correct. But when I ran this formula on the date range, I missed 25 records. I found out that this was because some clients had invoices on more than 1 date. But if this is the case, I want to count them on both dates.
I've been thinking about creating a sort of loop, counting the new invoices on each specific date, and then adding them up. But I'm not sure how to do this. Is there anyone who can help me with this? Or who has a different solution?
Thanks in advance
Gerben
|
IP Logged |
|
rkrowland
Senior Member
Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
|
Posted: 28 Mar 2012 at 12:45am |
Well if you're running the report to only show invoices within the date period can't you just count the total records returned?
If not, another option would be to group by date and then do a countdistinct by customer id on each day;
distinctcount({client.clientid},{table.date})
However, if a client has 2 invoices on the same day you'd be faced with your original problem where it would only be counted once.
Regards,
Ryan.
|
IP Logged |
|
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|
Posted: 28 Mar 2012 at 12:52am |
hi Ryan,
Thanks for your reply. If a client has more then 1 invoice on the same day, it should count as only one. But if the client has invoices on more then one date, he should be counted for onces for every date. Do I make sense?
KR
Gerben
|
IP Logged |
|
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|
Posted: 28 Mar 2012 at 1:39am |
The invoices must be shown within a certain date range btw. This is set up by parameters
|
IP Logged |
|
rkrowland
Senior Member
Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
|
Posted: 28 Mar 2012 at 2:10am |
Group by Client_Name;
Create a formula, we'll call it @day;
@day
datediff("d",#01/01/1901#,{table.datefield})
Now create another formula as follows;
This will count the number of separate days invoices were processed for each client.
Regards,
Ryan.
Edited by rkrowland - 28 Mar 2012 at 2:12am
|
IP Logged |
|
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|
Posted: 28 Mar 2012 at 2:23am |
The counts works. But how exactly does this help with the total count? The amount of invoices change each time they are loaded into the database.
|
IP Logged |
|
rkrowland
Senior Member
Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
|
Posted: 28 Mar 2012 at 2:25am |
Crystal can only count the records that are returned, unless you manually enter the previous total each time you run the report the only way to return the total is to run the report for all invoices without any date parameters.
Regards,
Ryan.
|
IP Logged |
|
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|
Posted: 28 Mar 2012 at 3:00am |
I mean, how does this formula helps me to get the result as described earlier? Is it even possible what I want?
|
IP Logged |
|
rkrowland
Senior Member
Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
|
Posted: 28 Mar 2012 at 3:38am |
If what you want is a total of all invoices ever while still only returning a list of invoices between certain dates then no, it isn't possible as per the reason in my previous post.
Thanks,
Ryan.
Originally posted by rkrowlandCrystal can only count the records that are returned, unless you manually enter the previous total each time you run the report the only way to return the total is to run the report for all invoices without any date parameters.
|
IP Logged |
|
Gurbs
Senior Member
Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
|
Posted: 28 Mar 2012 at 3:43am |
No, that is not what I am looking for. I want to have the count of cases loaded per unique client, within a certain date range. Problem is, that if this unique client has invoices on more than 1 date within this date range, it still counts 1. If the unique client shows up on more then 1 date, I want to count him once for every date he shows op within that date range
|
IP Logged |
|
|