问题
Is there a way to create a calculated measure that can do a distinct count, but excluding the null values? For example, if I have: 10, 20, 20, null; the distinct count is 3, but can I have the answer as 2?
回答1:
put a where condition to where the measure is not null
回答2:
you could try this:
with cte ( "counter" ) as
(
select
1 as "counter"
from
"YOURTABLE"
group by
"COLUMNNAME"
having ( "COLUMNNAME" IS NOT NULL )
)
select SUM( "counter" ) from cte
@ edit:
quite easier variant:
SELECT COUNT( DISTINCT "COLUMNNAME" ) FROM "TABLENAME"
回答3:
have the same issue - it is amazing microsoft ignores it...looks like the only solution is to build a view for distinct count measure group
http://www.sqlservercentral.com/Forums/Topic810069-17-1.aspx#bm1213461
回答4:
Thank you for all the answers. However, here I found a solution that works best for my need: http://richardlees.blogspot.com/2008/10/alternative-to-physical-distinct-count.html
By creating a Calculated Member using the following:
count(nonempty({[DimName].[HierarchyName].[LevelName].members-[DimName].[HierarchyName][All].UNKNOWNMEMBER},[Measures].[MyMeasure]))
回答5:
simply add where value is not null and value "!=''" that should do the trick
来源:https://stackoverflow.com/questions/13914039/distinct-count-to-exclude-null