Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: distincount without empty records Post Reply Post New Topic
Author Message
Memoli28
Groupie
Groupie
Avatar

Joined: 10 Apr 2009
Online Status: Offline
Posts: 58
Quote Memoli28 Replybullet Topic: distincount without empty records
    Posted: 15 Nov 2011 at 2:52am

Hi All,

Can someone please help me with following:

I grouped the records per order and put a summary field on this grouplevel
to count the distinctvalues of field1.

however, it counts also an empty field as 1, but i want to exclude this.

does anybody know how to do this?

the new summary will be put in the Group header.


example:
Group 1 : Order

             FIELD1:
record1:    A
record2:    A 
record3:    B
record4:    C
record5:  
record6:    D
  
distinctcount of FIELD1 on Grouplevel1 and exclude empty fields.

so, value should be 4 in this case.

regards,
Memoli 

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Nov 2011 at 3:36am
you can use a running total or variable formulas for this.
I prefer the RT process so her is that version
New RT
Name=DC_of_Field1 (or whatever)
Field to summarize=Field1
Type=distinctcount
evaluate= use a formula
table.field1<>""
reset=on change of group (group1)
place in group1 footer (or details to see row level incrimental changes)


Edited by DBlank - 15 Nov 2011 at 3:36am
IP IP Logged
Memoli28
Groupie
Groupie
Avatar

Joined: 10 Apr 2009
Online Status: Offline
Posts: 58
Quote Memoli28 Replybullet Posted: 22 Nov 2011 at 12:38am
Thanks Dblank...Smile
 
i also found another solution by google:
If you want to know how many records meet a criteria, you use an If-Then-Else formula as described in formula 10 and sum the formula.

However, if you need to do a distinct count of a field in these records, you run into a problem.  The records that don't meet the criteria have an else value that also gets counted.  The result is that your distinct count  is usually one higher than it should be.  Some CR users assume that if they simply skip the else line of the formula, that CR will use a NULL value as the else, and then the NULL wouldn't be counted.  However, CR does not use an else of NULL by default.  It will use the default value for the data type of the THEN value. That usually means and empty string value ("") or a zero for numerics.  But here is a way to fool CR into returning a NULL value as your ELSE value:

1) Create a formula called @null and save it without any contents

2) Create an if-then-else formula:

                         if {criteria.field} = "X"   //whatever your criteria is
                         then {table.ID}            //the field you are distinct counting
                         else {@null}               // the formula field you created above
                                                  // if your THEN field is a number use Val ({@null}) or ToNumber ({@null}) as your ELSE 

3) Do distinct counts of the if-then-else formula. 

in your case i have to put it in the group footer.
in this case i can put it also in the group header.
 
thanks for your help.
 
regards
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Nov 2011 at 12:02pm
Thanks for posting this solution Memoli. It is an interesting option for those that want to display conditional summaries in headers without using subreports.
IP IP Logged
Memoli28
Groupie
Groupie
Avatar

Joined: 10 Apr 2009
Online Status: Offline
Posts: 58
Quote Memoli28 Replybullet Posted: 29 Nov 2011 at 7:49am

you're welcome Dblank. Smile
I appreciate your great input on this forum.Thumbs%20Up

by the way,interesting comment about sub-reports.

I am most of the time creating reports and put it in one
blank report as 'sub-reports'.
no linking or summaries at all.

but is it possible to do the following:

create a mainreport

create sub-report A

create sub-report B

and link them together.(How you should do this i dont know)

and do for example a summary in sub-report A and put this value in the main report?
and also the same for sub-report B?

I use multiple files in database expert but can't find a way to logically
link them together.
example:
Some files are on order level/ some on order-line level/ some on packaging-level etc.
multiple order-lines in one packaging or vice versa.


regards,
Memoli

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Nov 2011 at 8:22am
you can ink the main report to a subreport and have some data fromt he main report define the data in the subreport.
When you insert a subreport you can right click on it and select the 'change subreport links'
A box opens which allows you to select the data element(s) fromt he main report and how you want to link it to the subreport.
Just keep in mind that the value used when passing is based on the value that exsits for that line/section in the main report.
 
You can also pass values back and forth using shared variables. Just keep in mind that the values has to be created and then passed on so if you are taking a value from a subreport back to the main report the shared variable int hemain report must be placed below the section that the subreport is in.
also suppressed subreports do not run so no shared variable can be passed. Tere are tricks around it if you need it.
IP IP Logged
Memoli28
Groupie
Groupie
Avatar

Joined: 10 Apr 2009
Online Status: Offline
Posts: 58
Quote Memoli28 Replybullet Posted: 02 Dec 2011 at 8:15am
thanks Dblank.
A new world of reporting is opened for me.
I am starting a new topic about sub-reports.
 
regards
Memoli
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.