Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Formula to iterate through multiple columns Post Reply Post New Topic
Page  of 2 Next >>
Author Message
Matt_123
Newbie
Newbie


Joined: 19 Jul 2010
Online Status: Offline
Posts: 5
Quote Matt_123 Replybullet Topic: Formula to iterate through multiple columns
    Posted: 19 Jul 2010 at 12:38pm
Hi,

My issue is a little difficult to explain. I'm working in Crystal Reports XI and I have a situation where I need to basically read through fields across multiple columns for values and count each time the field for the column is null or not.

Here it is another way: A person can have no, one, or more 'options' selected. Each 'option' is its own column that either is null or contains data labeling it true. I need the report to list out each 'option' and count the total times that 'option' is true for a set of people.

In the original code I was given had a formula containing
'if {Table1.a} <> "" then "a"
else if {Table1.b} <> "" then "b"
else if {Table1.c} <> "" then "c"
...'
where the report was grouped on this formula, and distinct counts of unique ids were taken to show the number of times each person had an option selected.

The problem being it only counts the first column it comes across as true, so it misses data. I need it to continue through each possible column. I can't change the database and the most direct way (hard coding each formula) is extreamley time-consuming (100+ formulas). I've attempted creating loops but I'm still too unfamiliar with crystal and have not been successful.

Is there a way for crystal to do this? Any help would be fantastic.
-Matt
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Jul 2010 at 2:35pm
can you post morte real samples
IP IP Logged
Matt_123
Newbie
Newbie


Joined: 19 Jul 2010
Online Status: Offline
Posts: 5
Quote Matt_123 Replybullet Posted: 20 Jul 2010 at 7:46am
Thanks for ther reply,
Here is perhaps a better description:
 
I have multiple columns (that I simply represented as "{table1.a}, {table1.b}, and {table1.c}" above). I need the formula to iterate through each one and check if it is null or not. Then I need it to return a string that I designate (represented as "a, b, and c" above) which I can group on. Ideally, I need it to return the string even if it is null but crystal seems to have some quirks when it comes to that.

Once I've grouped on the formula I can run distinct counts (and percentages) on two unique IDs (this in particular scenario I have {client_id} and {visit_id} where clients can have multiple visits and I need to count how many clients that outcome is true for and how many visits that outcome is true for).

In short: I need to create a grouped list of multiple {table.columns} and then run distinct counts of ids on them like you would with one {table.column}.

The original code of
'if {table1.a} <> "" then "atext"
else if {table1.b} <> "" then "btext"
else if {table1.c} <> "" then "ctext"
...'
does basically what I need it to except it stops at the first IF statement that is true (and doesn't list the values that are not true). I think what I need is functionally a 'if - then, if - then, if- then..." list or something wacky.

Please let me know if this doesn't make any sense and specify what you would like to see. I might be going at the report the wrong way...
 
Thanks,
-Matt
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Jul 2010 at 8:05am
I think there is an easier way.
You can use Running Totals to conditionally include or exclude rows.
For your patients make a Running Total
Right click on RT and select NEW
name=PatientCount
Field to sumamrize= patientID
Type=DistinctCount
Evaluate=Use a formula
//Need to tell me the logic for include or exclude here//
Reset=Never
Place in report footer
 
Same thing for visits but change it to the visitID


Edited by DBlank - 20 Jul 2010 at 8:06am
IP IP Logged
Matt_123
Newbie
Newbie


Joined: 19 Jul 2010
Online Status: Offline
Posts: 5
Quote Matt_123 Replybullet Posted: 20 Jul 2010 at 10:42am

I see what you mean, Running Totals might work.

Question, what kind of formula are you suggesting for the 'Evaluate' section?
 
I was thinking about doing a Reset on group (since I need to display counts for every outcome) but the issue I'm running into is that I don't have a single column to group by. Each outcome is its own column and I'd need to combine multiple columns into one group (which I think was the idea behind the original formula). And by that method I'd need some way to force crystal to go through each IF statement. However, that is probably the wrong way to approach it.
 
Thanks for the replies,
-Matt
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Jul 2010 at 10:46am
Can a row fall into more than one outcome?
If so don't group on it or it will screw up your numbers.
 
Can you give me a real example of soemthing that needs to be counted and some data rows and I can write a formula for a RT to count them.
IP IP Logged
Matt_123
Newbie
Newbie


Joined: 19 Jul 2010
Online Status: Offline
Posts: 5
Quote Matt_123 Replybullet Posted: 20 Jul 2010 at 11:36am

Yes, a client can have more than one outcome.

Would something like this work?:
 
Client_ID, Visit_ID, OC_1, OC_2, OC_3, OC_4
01,              v01,    123,    null,    789,    null
01,              v02,    123,    null,    null,    221
02,              v03,    null,    null,    789,    221
03,              v04,    123,    456,    null,    221
 
*each outcome(OC) has a code associated to it.
 
Results would show as:
Type                  Clients    %   Visits   %
Outcome_1             2      66%     3    75%
Outcome_2             1      33%     1    25%
...
 
This is basically what I'm trying to accomplish, let me know if you need more information.
 
The actual report is even a bit more complex in that I need to set up a heirarchy based on other columns in this table - where say
Outcome_1 ....
         Outcome_2....
                  Outcome_3....
         Outcome_4....
But I'm not touching that yet.
 
Thanks!,
-Matt
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Jul 2010 at 11:42am

so you need to count the number of clinets that have at least one non null value in one of the OC fields.

in the RT use an evaluate formula of:
NOT (isnull(OC_1) and isnull(OC_2) and isnull(OC_3) and isnull(OC_4))
 
Is that the count you are after here?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Jul 2010 at 11:43am
Note that RTs have to be placed after the last record evaluated to see teh total (don't use them in headers) so in this case it needs to be in the report footer.
You can place it on a details line and see the actual counting process...
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 20 Jul 2010 at 11:46am
as an FYI Crystal is squirrely with NULLs.
It will stop evaluating on Nulls so that was part of the issue you originally had.
If you use Nulls in the formula you have to use them first. You can also flip the formula option (or report option) from 'using Nulls' to 'Use default values for Nulls' to help avoid that problem. That being said sometimes you still need to know the difference between Null, "" and not "" so it is nice to turn the feature on and off.


Edited by DBlank - 20 Jul 2010 at 11:48am
IP IP Logged
Page  of 2 Next >>
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.