Print Page | Close Window

distincount without empty records

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=14940
Printed Date: 05 May 2024 at 12:19pm


Topic: distincount without empty records
Posted By: Memoli28
Subject: distincount without empty records
Date 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 




Replies:
Posted By: DBlank
Date 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)


Posted By: Memoli28
Date 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


Posted By: DBlank
Date 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.


Posted By: Memoli28
Date 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



Posted By: DBlank
Date 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.


Posted By: Memoli28
Date 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



Print Page | Close Window