Unix Technical Forum

Measure with "Distinct Count" Aggregate Function and Null value

This is a discussion on Measure with "Distinct Count" Aggregate Function and Null value within the SQL Server Data Warehousing forums, part of the Microsoft SQL Server category; --> I Have a cube with many measures. One of them use as "Aggregate Function" the function "Distinct Count". But ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server Data Warehousing

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 06:43 PM
Paulo Andre Ortega Ribeiro
 
Posts: n/a
Default Measure with "Distinct Count" Aggregate Function and Null value


I Have a cube with many measures. One of them use as "Aggregate
Function" the function "Distinct Count". But some records of fact table
has null value in the field of this measure. In SQL Server, when I
execute a "SELECT COUNT (DISTINCT field)" command, it eliminates the
Null value, as showed in the next exemple:

Table X

field A
1122
2345
4567
1122
1122
2345
null
null

When a execute the command:
SELECT COUNT (DISTINCT A) FROM X
I recieve "3" as result.

But when I create a measure over the field A in a cube and I choose the
aggregate funtion "Distinct Count", I recieve "4" as result. I think
that Analysis Services is considering "null" as one of distinct values
of the field A, but I don´t want that, because it makes no sense for me.

Is there a way to eliminate the null value in Analysis Services, to show
"3" as the result in the same way I receive in SQL Server?

Thanks,

Paulo


*** Sent via Developersdex http://www.developersdex.com ***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 06:43 PM
Dino Hsu
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null value

I am new to SQL server, but experieced in Oracle.
My top of mind test would be:
select count(distinct *) from x => 4
select count(distinct a) from x => 3
It's standard SQL behaviour, I think.
pls verify, tks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 06:43 PM
Paulo Andre Ortega Ribeiro
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null value

When a execute the command "select count(distinct *) from x" , I recieve
"4" as result and when a execute the command "select count(distinct a)
from x", I recieve "3" as result.

But my problem is not with SQL Server. My problem is in Analysis
Services. I created a measure over the field "a", with the aggregate
function "Distinct Count". But the result in Analysis Services is "4"
and not "3", as I expected.

Do you have a clue?

Thanks,

Paulo


*** Sent via Developersdex http://www.developersdex.com ***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 06:43 PM
Jéjé
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null value

try to create a new cube (copy/paste the current one)
then create a view on the database like:
select * from mytable where mycolumntodcount IS NOT NULL

use this view in the new cube.
this cube will contain only the dcount measure and the null values are
ignored.

"Paulo Andre Ortega Ribeiro" <paulo.andre.66@terra.com.br> wrote in message
news:ehCLkEZAGHA.2272@TK2MSFTNGP11.phx.gbl...
> When a execute the command "select count(distinct *) from x" , I recieve
> "4" as result and when a execute the command "select count(distinct a)
> from x", I recieve "3" as result.
>
> But my problem is not with SQL Server. My problem is in Analysis
> Services. I created a measure over the field "a", with the aggregate
> function "Distinct Count". But the result in Analysis Services is "4"
> and not "3", as I expected.
>
> Do you have a clue?
>
> Thanks,
>
> Paulo
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 06:43 PM
Paulo Andre Ortega Ribeiro
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null value


I tried this solution and It works. But I don´t want to create a new
cube. That will be my last option. Is not possible to ignore the null
vules with "distinct count" as the aggregate function? Is not there a
propriety that I can configure?

Thanks,

Paulo


*** Sent via Developersdex http://www.developersdex.com ***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 06:43 PM
=?Utf-8?B?RXJpayBWZWVybWFu?=
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null valu

Even if you didn't have the NULL challenge with Distinct Count, creating a
separate cube for the Distinct Count is a best practice. There are
aggregation and query performance benefits.

The dimensional granularity to the distinct count cube (with the NOT NULL
filter) would be identical to the other cube, so any queries against the
virtual cube would not require any special calculations.

Erik
----
Erik Veerman
erik (at) solidqualitylearning.com

"Paulo Andre Ortega Ribeiro" wrote:

>
> I tried this solution and It works. But I don4t want to create a new
> cube. That will be my last option. Is not possible to ignore the null
> vules with "distinct count" as the aggregate function? Is not there a
> propriety that I can configure?
>
> Thanks,
>
> Paulo
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 06:43 PM
Jéjé
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null value

the only other option I can propose is:
add a dimension in the cube, add a column in the fact table called "ToCount"
which contains a Y/N or 0/1 value linked to this new dimension.
case when MyColumn is null then 'N' else 'Y' end as ToCount

hide the dimension.
Rename the dcount measure to HiddenDcount, hide this measure
create a calculated measure which is:
(measures.HiddenDCount, MyDummyDimension.&[Y])
this ignore the null values.


"Paulo Andre Ortega Ribeiro" <paulo.andre.66@terra.com.br> wrote in message
news:u9ciH0kAGHA.2040@TK2MSFTNGP14.phx.gbl...
>
> I tried this solution and It works. But I don´t want to create a new
> cube. That will be my last option. Is not possible to ignore the null
> vules with "distinct count" as the aggregate function? Is not there a
> propriety that I can configure?
>
> Thanks,
>
> Paulo
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-27-2008, 06:43 PM
=?Utf-8?B?RXJpayBWZWVybWFu?=
 
Posts: n/a
Default Re: Measure with "Distinct Count" Aggregate Function and Null valu

Here another idea:
Add a hidden measure "NULL_Exists" that's a 0 or 1 based on whether the
distinct count column is NULL or not (Null=1). Use the MAX aggregate type
(the result telling you whether there was a null or not across the
dimensionality you are looking at)
Use a calculated measure that = [DistinctCountMeasure] - [NULL_Exists]

So, if there wasn't a NULL, the NULL_Exists returns a 0 and the distinct
count isn't changed. If there was a NULL, then the result is the distinct
count - 1.

----
Erik Veerman
erik (at) solidqualitylearning.com


"Jéjé" wrote:

> the only other option I can propose is:
> add a dimension in the cube, add a column in the fact table called "ToCount"
> which contains a Y/N or 0/1 value linked to this new dimension.
> case when MyColumn is null then 'N' else 'Y' end as ToCount
>
> hide the dimension.
> Rename the dcount measure to HiddenDcount, hide this measure
> create a calculated measure which is:
> (measures.HiddenDCount, MyDummyDimension.&[Y])
> this ignore the null values.
>
>
> "Paulo Andre Ortega Ribeiro" <paulo.andre.66@terra.com.br> wrote in message
> news:u9ciH0kAGHA.2040@TK2MSFTNGP14.phx.gbl...
> >
> > I tried this solution and It works. But I don´t want to create a new
> > cube. That will be my last option. Is not possible to ignore the null
> > vules with "distinct count" as the aggregate function? Is not there a
> > propriety that I can configure?
> >
> > Thanks,
> >
> > Paulo
> >
> >
> > *** Sent via Developersdex http://www.developersdex.com ***

>
>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com