Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Distinct Count based on condition Post Reply Post New Topic
Author Message
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Topic: Distinct Count based on condition
     Posted: 11 Mar 2015 at 6:02am
Hello,
I am using a crosstab with formulas to try to get a distinct count based on {Event.key} only if {Messaging.Recipient} like "*PCT*"

I am grouping on the {event.key}.

My problem is there is multiple {Messaging.Recipient} like *PCT* for each event but so I basically I need if there is a PCT under the key then count.

IF {Reports_Messaging_Recipients.FriendlyName} like "*PCT*" THEN DISTINCTCOUNT({Reports_Messaging_Recipients.FriendlyName},{Reports_Events.Key})
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Mar 2015 at 6:21am
you want the results in a crosstab?
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 11 Mar 2015 at 6:58am
Yes, because I have my other results in a cross tab
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Mar 2015 at 7:28am
you can try a NULL trick
create a formual field called "Null"
leave it entirely empty
create another formula field called "Whatever"
in this formula use
IF {Reports_Messaging_Recipients.FriendlyName} like "*PCT*" then {event.key} else tonumber({@Null})
 
IN your Crosstab use a summary of "@Whatever" as a distinctcount
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 12 Mar 2015 at 6:17am
Its still counting every time there is a PCT underneath the key with the same key. I need it to only count once per key that has PCT in the table.

Thanks for the help!
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 12 Mar 2015 at 6:26am
I think I got it ---
IF {Reports_Messaging_Recipients.FriendlyName} like "*PCT*" AND {Reports_Events.EventID}<> previous({Reports_Events.EventID}) then {Reports_Events.Key} else ({@Null})

Thanks for taking a look!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Mar 2015 at 6:34am
your process will work but to get any results to function in a crosstab can be tricky.  
It will display the EventID on every row where the name is like PCT but using a distinct count of that formula result will disregard the duplicates in your summarization and the NULL responses are exlcuded from the summary as well.


Edited by DBlank - 12 Mar 2015 at 6:54am
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 12 Mar 2015 at 8:11am
That is exactly what I am looking for. I want to get a unique count of records and avoid duplicates and when null responses are given.
IP IP Logged
nhopp4
Groupie
Groupie


Joined: 03 Oct 2012
Location: United States
Online Status: Offline
Posts: 62
Quote nhopp4 Replybullet Posted: 12 Mar 2015 at 10:10am
I spoke too soon. With multiple rows it will not pick up the PCT count. I think the previous is too far before so it nulls them. Any other ideas?

Thanks!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Mar 2015 at 10:16am

I am confused.

I recommended you not use the previous() and just use the original formula I gave you. Your original request was about summarization via a Cross Tab (CT), not display on a row. What about the CT soluion is not accurate?
Also be careful to avoid the trap of how something displays in Crystal and how it calculates summary data.  These two things are very different.


Edited by DBlank - 12 Mar 2015 at 10:16am
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