Distinct count that ignores NULL
I am trying to do a distinct count of a field but I do not want any NULL rows to be counted. Any ideas on how to accomplish this?
I have created a formula field that returns a date from a different field if certain criteria are met. If not, it returns " ". Now I need to get a distinct count of the dates. I am not very experienced using Crystal and this has me stumped.
You can also use a Running Total
Select the field to be counted, select distinct count from summary list
In the evaluate section check formula
In formula editor
not(isnull(yourfield))
In the reset section check the appropriate level for resetting.
Ian
Similar Messages
-
Distinct Count of Non-null Values
I have a table that has one column for providerID and then a providerID in each of several columns if the provider is under a particular type of contract.
I need a distict count of each provider under each type of contract for every county in the US.
distinct count is almost always one more than the actual distict count because most counties have at least one provider that does not have a particular contract and the distict count counts the null value as a distict value.
I know I can alter the fields to have a zero for nulls, ask for a minimum count and then subtract 1 from the distict count if the minimum is zero, but I hope there is an easier way to figure distict counts of non-null values.
any suggestions?
Thanks,
JenniferHello,
*I need a distict count of each provider under each type of contract for every county in the US*
To the above requiremetn,
I will suggest the following approach.
Use group expert formula for country, contract and provider.
Now you will have the hierarchy to which level you want to apply distinct count. You can do it as suggested by ken hamady.
Regards
Usama -
The distinct count issue?
Hello experts,
So, I have an OBI report (table view). I needed to get the percentage difference btn 2 columns, I did. Then I had to summarize difference in 4 buckets (0-15, 16-30, 31-50, >50%); I did (case statement). NOW, I need to summarize(distinct count) the above buckets based on Store numbers for each day.
Basically, if the difference is btn(0-5%) and I have 5 stores then I need to see 5 stores separately. The problem I am having when I do the distinct count instead of having the counts separately for each bucket I am getting the total. I see the buckets summarized, but the store column is showing the total number of all(we have about 700 stores) instead of breaking down the count for each bucket. In the stores column I am using the distinct count function, I don't know if the problem is here or the case statement.
I know its Friday, still I believe there is someone who might have an idea on my dilemma.
As always, your insights are highly appreciated,Header 1
Header 2
Header 3
Header 4
Header 5
Header 6
Date
Store Count
Sales
Todate Sales
Difference %
Difference buckets
03/24/2013
698
716,374
717,011
-0%
0-15%
03/25/2013
698
583,335
583,793
-0%
0-15%
03/26/2013
698
220,640
220,886
-0%
0-15%
03/27/2013
698
236,803
188,150
215
11-30%
Header 8
Srini,
I am still not good at using OTN tables, but above is what I am talking about. Basically, The store count should not show the total count of all stores, instead it should show only distinct count that within the percentage bucket. As u can see it gives me the total, I made sure the aggregate rule isn't sum. By the way, could the problem be the case statement not the store column..
I also tried bucket and store only, still it shows the sum of all stores and not just distinct.
any idea -
<p>I have a report that gets a distinct count of items per day.</p><p>DistinctCount(, , "daily")</p><p> I would like to create a running total of the daily count for a weekly grand total.</p><p>Thanks!</p>
<p>I'll take a stab at this - So I understand that the report is grouped by Day and looks like this:</p><p>GF1: 1/1/07 9</p> <p>GF1: 1/2/07 10</p> <p>GF1: 1/3/07 12</p> <p>GF1: 1/4/07 15</p> <p>GF1: 1/5/07 20</p><p> </p><p>The first thing I'd try is to create a another group on your Date field, this time selecting the grouping option to be "For Each Week". Take that group and move it so that it is Group1 and your current group is Group 2.... your structure will now look like this. </p><p>GH1: 1/1/07 < new 'week' grouping' > </p><p> GF2: 1/1/07 9</p> <p> GF2: 1/2/07 10</p> <p> GF2: 1/3/07 12</p> <p> GF2: 1/4/07 15</p> <p> GF2: 1/5/07 20</p><p> Then I would copy the Sum field (distinct count) that you are using in Group 2 and put it in the Group 1 footer. We could also create a formula to sum up all distinct counts per day, but a Distinct Count by week should accomplish what you are after. Then in a seperate formula, you could divide the DistinctCount of orders (by week) by the DistinctCount of dates (by week) to get your daily average....</p><p>formula:</p><p>DistinctCount ({Orders.Order ID}, {Orders.Order Date}, "weekly") <br />/ <br />DistinctCount ({Orders.Order Date}, {Orders.Order Date}, "weekly") </p><p> </p><p>Hope that helps. </p>
-
how to ignore nulls in analytic functions ( row_number() and count())
Iam attaching test data can any one help me please
thanks in advanceeeee
CREATE TABLE TEMP_table
ACCTNUM NUMBER,
l_DATE TIMESTAMP(3),
CODE VARCHAR2(35 BYTE),
VENDOR VARCHAR2(35 BYTE)
insert into temp_table values (1,sysdate+1/60,'bso','v1');
insert into temp_table values (1,sysdate+2/60,'bsof','v1');
insert into temp_table values (1,sysdate+3/60,'bsof','v2');
insert into temp_table values (1,sysdate+4/60,'','v1');
ian executing this my ;
SELECT acctnum,l_date,vendor,code_1,
CASE
WHEN code = 'bsof'
AND COUNT (DISTINCT code) OVER (PARTITION BY acctnum, vendor) > 1
AND row_number () OVER (PARTITION BY acctnum, vendor ORDER BY vendor, l_date) != 1
THEN 'yes'
ELSE 'no' END result
FROM (select acctnum,l_date,vendor, code code_1, case when code IN ('bso', 'bsof') then code
else null end code from TEMP_TABLE
ORDER BY acctnum ,l_date);
my result :
1 3/23/2011 5:24:34.000 PM v1 bso no
1 3/23/2011 5:48:36.000 PM v1 bsof yes
1 3/23/2011 6:36:41.000 PM v1 bsof yes
1 3/24/2011 11:55:53.000 AM v1 no
1 3/23/2011 6:12:38.000 PM v2 bsof no
I need to eliminate nulls in top query not in inner query (not using where condition in inner query)
[\code] -
I have a multi-select parameter that can have a list of thousands of entries. In general, the user will pick a few entries from the list or "Select All". If they check "Select All", I would much prefer that I get a NULL or an empty string
instead of a list of all values. Is there any way to do that?
In experimenting with a work-around, I tried putting an "All" label with a null value in the list, but it is ignored (does not display in the drop-down). If I use an empty string for the value, my "All" entry does get displayed, but so
does "Select All", which is confusing. Is there a way to suppress "Select All"?
- MarkI adapted the following from a workaround posted by JNeo on 4/16/2010 at 11:14 AM at
http://connect.microsoft.com/SQLServer/feedback/details/249227/multi-value-select-all-parameter-in-reporting-services
To get a null value instead of the full list of all values when "Select All" is chosen:
1) Add a multi-value parameter "MyParam" that lists the values to choose.
2) Add a DataSet "ParamCount" identical to the one used by "MyParam", except that it returns a single column named [Count] that is a COUNT(*) of the same data
3) Add a parameter "MyParamCount", set it to hidden and internal, then set the default value to 'Get values from a query', choosing "ParamCount" for the Dataset and the one [Count] column for the Value field.
4) Change the parameter for the main report DataSet so that instead of using [@MyParam], it uses this expression:
=IIF(Parameters!MyParam.Count =
Parameters!ParamCount.Value, Nothing, Join(Parameters!MyParam.Value, ",")) -
Distinct count using lookup table
How can I get a distinct count of column values using a different table?
Let's say I want to get a distinct count of all "company_name" records in table "emp" that corespond (match) with "lookup" table, "state" category.
What I want is to find counts for all companies that have a value of "california" in the "state" column of the "lookup" Table. I want the output to look like:
Sears 17
Pennys 22
Marshalls 6
Macys 9
I want the result to show me the company names dynamically as I don't know what they are, just that they are part of the "state" group in the lookup Table. Does this make sense?
MMark,
In the future you might consider creating test cases for us to work with. Something similar to the following where sample data is created for each table as the union all of multiple select statementsselect 'INIT_ASSESS' lookup_type
, 1 lookup_value
, 'Initial Assessment' lookup_value_desc
from dual union all
select 'JOB_REF', 2, 'Job Reference' from dual union all
select 'SPEC_STA', 3, 'SPEC STA' from dual;
select 'INIT_ASSESS' rfs_category
, 1 val
from dual union all
select 'JOB_REF', 1 from dual union all
select 'JOB_REF', 1 from dual union all
select 'SPEC_STA', null from dual;Then we can either take your select statements and make them the source of a CTAS (create table as) statementcreate table lookup as
select 'INIT_ASSESS' lookup_type
, 1 lookup_value
, 'Initial Assessment' lookup_value_desc
from dual union all
select 'JOB_REF', 2, 'Job Reference' from dual union all
select 'SPEC_STA', 3, 'SPEC STA' from dual;, or include them as subfactored queries by using the with statement:with lookup as (
select 'INIT_ASSESS' lookup_type
, 1 lookup_value
, 'Initial Assessment' lookup_value_desc
from dual union all
select 'JOB_REF', 2, 'Job Reference' from dual union all
select 'SPEC_STA', 3, 'SPEC STA' from dual
), RFS as (
select 'INIT_ASSESS' rfs_category
, 1 val
from dual union all
select 'JOB_REF', 1 from dual union all
select 'JOB_REF', 1 from dual union all
select 'SPEC_STA', null from dual
select lookup_value_desc, count_all, count_val, dist_val
from lookup
join (select rfs_category
, count(*) count_all
, count(val) count_val
, count(distinct val) dist_val
from RFS group by rfs_category)
on rfs_category = lookup_type;Edited by: Sentinel on Nov 17, 2008 3:38 PM -
MSSQL2005 Analysis Service Distinct Count
hi,
i am currently trying to build a distinct count on my cube (mssql2005 analysis services).
But after i added the discount count on the field i want to and start the processing, the following errors appear.
- Errors in the OLAP storage engine: The sort order specified for distinct count records is incorrect.
- Errors in the OLAP storage engine: An error occurred while processing the 'FACT VIEW STATISTIC' partition of the 'FACT VIEW STATISTIC 1' measure group for the 'Accident Statistic' cube from the OLAP_PROJECT database.
the count measure works fine.
will appreciate any help on this distinct count problem.
thanks in advance.
HYI also received this error:
"Errors in the OLAP storage engine: The sort order specified for distinct count records is incorrect. "
Running SQL Server 2005 SP2 Enterprise Edition
The collation between SQL Server and Analysis Services was the same.
The distinct count was on a character data type.
There were no NULLs in the data.
The cube was processing fine until new data was added.
After some investigation into the data it seems that the culprit was one row that the data length was 13 characters on the column of the distinct count. Everything else was less than 13 characters. (See results below). Updating this one row solved the problem. The exact value of the data is: '1-4296-175-9'
Here is a result set:
select len(columnname) as data_length, count(*) as count
from [tablename]
group by len(columnname)
order by data_length
data_length count
2 3
5 1
6 3
7 2
9 1
10 856
13 1
My question though is if SQL2005 can do distinct counts on strings then why choke on one row with an extra length? -
Regular measures(measures with SUM function) are not working along Distinct count measures
Hi All,
I am creating a cube that got to have a distinct count measure and a sum measure. if i have created only sum measure then it is working fine. if i create both measures and process the cube only distinct count measure is populated. the sum measure is showing
all blank values. i am using 2008 R2, and creating 2 different measure groups for both measures, after i include the distinct count measure the sum measure becoming null. can you please help me with this? i am breaking my head for last 2 days on this.. Thank
YouRamesh, measures are affected by the context of the queries that contain them, for example and in some cases, you can get a different total count of something by two different queries, this is because the context of the first query is different than
the second one ... keep this in mind.
Now, I've noticed that you are "creating 2 different measure
GROUPS for both measures", and i guess that you are trying to view those two measures _which are from different measure
groups_ at the same time and in the same report.
considering the info in the first point and as you are create the calculated measures in two different measure
groups, I'm not sure but i guess that this is the problem, and i suggest you create those two calculated measures
in the same measure group, then try to view them again and let's see.
if the previous point didn't solve it, please post the expressions you are using to create the calculated measures, maybe this will help in finding the problem. -
Specified Order Grouping does not show if Distinct Count is Zero
Post Author: Hieu
CA Forum: General
Hello,
I'm using Crystal Reports XI R2 with SQL data source. I have a cross-tab report with grouping in specified order. It's a report of applicants applying to a college. The grouping is of various majors (degrees). The report summarizes (distinct counts) the number of applicants for the groups of majors. The problem is that if the count for a group of major is zero, then that Named Group does not appear at all in the cross-tab report. I want the Name Group to appear with the count of "0".
I notice this same phenomenon with specified order grouping anywhere and not just in a cross-tab. I have tried changing "convert database/other null values to default" but nothing working yet.
Any help will be most appreciated. Thanks.Post Author: synapsevampire
CA Forum: General
It's not a phenomenon, it's how databases and SQL works.
You didn't get any rows back for those with a zero distinct count (otherwise the count would be 1 or more, right?), so Crystal doesn't show any data for those groups.
So to display a zero for those that do not exist would reuire either advanced SQL, or manual summaries.
One method for manual summaries is to use Running Totals. Select distinct count of the applicants and group by the majors, then in the evaluate use a formula place:
{table.majors} = "Blah 1"
Creating a seperate Running Total for every group and replacing "Blah 1" with the various majors.
-kai -
Distinct count of GRN's in Query PLD
hi all,
We have developed a daily grn report and designed report
using Query PLD.
Report contains
(grn no,date,vendor name,vendor ref no,item code,item
description,quanity & line total)
We want to display no of grn's(distinct count)
@ repetitive area footer.
Is there any function available in formula field to display
distinct count of no. of grn's ? / It should done thru query.
Thanks,
with regards,
A.Jeyakanthanit will be hard from PLD, instead u can have ur query like,
SELECT 'Details', ' ',T0.Docnum, T0.CardName, .... FROM OPDN T0 WHERE Month( T0.DocDate ) = Month ('{%0]')
Union
SELECT 'Counts', count(T0.DocNum) as 'Doc(s) No', ' ', ' ', ... FROM OPDN T0 WHERE Month( T0.DocDate ) = Month ('{%0]')
(Replace { with [ )
Note ' ' is a gap in order to fill the other fields. in first query have given tht ' ' gap purposely so tht the display will not affect ur designing part
union is used b'coz Count() fn is like aggregate, so wont allow further individual fields coming along with it.
the 2nd query will occupy only one row, which by grouping u can separate and can hide from repetitive and take the value via formula field by writing that field's id to it into Footer Area.
Regards,
Dhana.
Edited by: Dhanalakshmi C on Mar 5, 2008 1:31 PM -
Report using Tabular Model and Measures based on Distinct Counts
Hello,
I am creating a report that should present something like this:
YEAR-1 | MONTH-1 | MONTH-2 | MONTH-3... | YEAR | MONTH-1 | MONTH-2 | MONTH-3...
My problem is that when designing the dataset to support this layout I drag the Year, Month and Distinct count Measure, but on the report when I want the value for the YEAR level I don't have it and I cannot sum the months value...
What is the best aproach to solve this? Do I really have to go to advanced mode and customize my MDX or DAX? Can't basic users do something like this that seems so trivial and needed?
Thank you
Luis SimõesHi Luis,
According to your description, you create a Reporting Services report using Analysis Service Tabular Model as the datasource, now what you want is sum the months value on year level, right?
In your scenario, you can add the Month field to column group, add a parent group using Year Field and then add a Total on Month group. In this case, Reporting Services will sum the months value on Year level. I have tested it on my local environment, the
screenshot below is for you reference.
Reference:Lesson 6: Adding Grouping and Totals (Reporting Services)
If this is not what you want, please describe your dataset structure, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support -
How to get Distinct Count of Products across two dimensions
Hi,
I have two dimensions, Item and Presentations. I need to get distinct count of products for IMD_Id + Merc_Pres_Id. IMD_Id is the lowest member in Item and Merc_Pres_Id is lowest in Presentation. My MDX query is given below but when I apply filters to
slice it, it does not work and does not give right count. It always gives the count for all.
/* Last Year Demand - Demand for 12 months back of selected months */
With
Member [Measures].[LYDemand]
as
Sum(
Generate(
EXISTING[All Date].[Fiscal Month Name].[Fiscal Month Name].Members,
{parallelperiod([All Date].[Fiscal Month Name].[Fiscal Month Name], 12
,[All Date].[Fiscal Month Name].CurrentMember)}
,[Measures].[Proj Demand]
/* Last to last Year Demand - Demand for 24 back of selected months */
Member [Measures].[LLYDemand]
as
Sum(
Generate(
EXISTING[All Date].[Fiscal Month Name].[Fiscal Month Name].Members,
{parallelperiod([All Date].[Fiscal Month Name].[Fiscal Month Name], 24
,[All Date].[Fiscal Month Name].CurrentMember)}
,[Measures].[Proj Demand]
/* Current Year Active Products */
Member [Measures].[CYCount]
as
CASE
WHEN
[Measures].[Proj Demand] > 0
THEN
DistinctCount(Existing(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch
Pres Key].[Merch Pres Key])))
ELSE
NULL
END
/* Last year Active Products */
Member [Measures].[LYCount]
as
CASE
WHEN
[Measures].[LYDemand] > 0
THEN
DistinctCount(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch Pres Key].[Merch Pres
Key], [All Items].[Style Name].CurrentMember, (StrToMember('[All Date].[Fiscal Month Name].&[201401]',CONSTRAINED).Lag(12)
: StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED).Lag(12))))
ELSE
NULL
END
/* Last to last Year Active Products */
Member [Measures].[LLYCount]
as
CASE
WHEN
[Measures].[LLYDemand] > 0
THEN
DistinctCount(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch Pres Key].[Merch Pres
Key], [All Items].[Style Name].CurrentMember, (StrToMember('[All Date].[Fiscal Month Name].&[201401]',CONSTRAINED).Lag(24)
: StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED).Lag(24))))
ELSE NULL END
SELECT
[Measures].[CYCount], [Measures].[LYCount], [Measures].[LLYCount],
[Measures].[Proj Demand],[Measures].[LYDemand],[Measures].[LLYDemand]
ON
COLUMNS,
Non
Empty([All Items].[Demand Center Name].[Demand Center Name], [All Items].[Style Name].[Style Name])
ON ROWS
FROM
(SELECT (StrToSet('[All Items].[Style].[ALL]'))
ON COLUMNS
FROM
(SELECT (StrToSet('[All Items].[Demand Center].[ALL]'))
ON COLUMNS
FROM
(select (STRTOSET('[All Items].[Merch Group].&[MG-110]'))
on Columns
FROM
(SELECT (StrToSet('[All Merchandise Presentations].[Merch Pres Chnl Dkey].&[MPC-1]'))
ON COLUMNS
From
[FMI Forecasting]
WHERE {strToMember('[All Date].[Fiscal Month
Name].&[201401]',CONSTRAINED) :
StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED)}
Requirements are as follows:
1. Distinct Count should not include products where Proj Demand is 0, when I am using Filter function to remove products with 0 demand, query is really slow and execution time goes up from 35- 40 secs to 8-9 Minutes.
2. When we apply filter (parameters) Distinct Count should be in the context of filters( which are mentioned in the select statement like Style, Demand Center and Merch Group). Currently after applying filters count does not change.
Thanks for help.Hi Skd78,
Thank you for your question.
I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
Thank you for your understanding and support.
Regards,
Charlie Liao
TechNet Community Support -
Distinct count of dimension business key in fact table
In my cube I have a fact table which joins to a patient dimension. The patient dimension is a type 2. What I would like to do is get a distinct count of patients who have records in the fact table. The business key in the patient dimension
is the PrimaryMrn. So a SQL query would look like this.
SELECT count(distinct PrimaryMrn)
FROM EncounterFact e
INNER JOIN PatientDim p
on e.PatientKey = p.PatientKey
Is it possible to do this via MDX?
Thanks for the help.If you have to distinct count an attribute in a SCD 2, you might choose between:
Denormalizing that attribute in the fact table, and the create a classical DISTINCT COUNT measure
Use a many-to-many approach - see the "Distinct Count" scenario in the Many-to-Many White paper here:
http://www.sqlbi.com/articles/many2many (for both Multidimensional and Tabular
If you use Tabular, you might want to read also this pattern:
http://www.daxpatterns.com/distinct-count/
Marco Russo http://www.sqlbi.com http://www.powerpivotworkshop.com http://sqlblog.com/blogs/marco_russo -
Distinct count for multiple fact tables in the same cube
I'm fairly new to working with SSAS, but have been working with DW environments for many years.
I have a cube which has 4 fact tables. The central fact table is Encounter and then I also have Visit, Procedure and Medication. Visit, Procedure and Medication all join to Encounter on Encounter Key. The relationship between Encounter
and Procedure and Encounter and Medication are both an optional 1 to 1. The relationship between Encounter and Visit is an optional 1 to many.
Each of the fact tables join to the Patient dimension on the Patient Key. The users are looking for a distinct count of patients in all 4 fact tables.
What is the best way to accomplish this so that my cube does not talk all day to process? Please let me know if you need any more information about my cube in order to answer this.
Thanks for the help,
AndyHi Andy,
Each distinct count measure cause an ORDER BY clause in the SELECT sent to the relational data source during processing. In SSAS 2005 or later, it creates a new measure group for each distinct count measure(it's a technique strategy for improving perormance).
Besides, please take a look at the following distinct count optimization techniques:
Create Customized Aggregations
Define a Processing Plan
Create Partitions of Equal Size
Use Partitions Comprised of a Distinct Range of Integers
Distribute the Hash of Your UserIDs
Modulo Function
Hash Function
Choose a Partitioning Strategy
For more detail information, please refer to the article below:
Analysis Services Distinct Count Optimization:
http://www.microsoft.com/en-us/download/details.aspx?id=891
In addition, here is a good article about SSAS Best Practices for your reference:
http://technet.microsoft.com/en-us/library/cc966525.aspx
If you have any feedback on our support, please click
here.
Hope this helps.
Elvis Long
TechNet Community Support
Maybe you are looking for
-
User defined Selection screen for Logical database
hi all, can we display a user defined selection screen instead of the default selection screen in LDB . eg pnp cheers senthil
-
IMac too heavy? Shifting down constantly.
I just recently purchased a new 20" iMac and I've noticed that my screen will slowly tilt down from gravity. Without any thumps on the desk or vibration from walking around, just leaving the room and coming back 10 minutes later it will have shifted
-
HI GURUS, PLESAE LET ME KNOW... WHETHER *PO CANCELLATION LETTER..*. POSSIBLE WITH STANDARD SAP.. BY CREATING NEW MESSAGE ... OUTPUT OR SOMETHING PLS PROVIDE YOUR VIEWS AND SUGGEST tHANKS
-
Hi, I'm not sure if there's just no information in the .ics file or what, but the NASCAR schedule isn't showing up in my iCal. Dave
-
Why can't I see my Itunes library when I connect to the computer?
I want to see what songs are in my Ipod with my new nano and with my mini, when plugged in to my computer I had the option to see every song in my device. I can't see any of my songs when I click on the Music tab. I need to change some of the file na