Forum Discussion
Anonymous
4 years agoNot applicable
Count Distinct by Grouping
Hi, This is a very simple thing but I cant seem to get to the bottom of it. I need to create a measure that gives me the count distinct by a grouping. For example TableA Group Attributes...
- 4 years ago
Anonymous , Try a measure
calculate(distinctcount(Table[Attributes]), filter(allselected(Table), Table[Group] = max(Table[Group] ) ) )
smpa01
4 years agoCommunity Champion
Anonymous try this
Measure2 =
CALCULATE (
COUNTX ( SUMMARIZE ( t2, t2[Group], t2[Attribute] ), t2[Group] ),
ALLEXCEPT ( t2, t2[Group] )
)
Measure3 =
CALCULATE (
SUMX ( VALUES ( t2[Group] ), CALCULATE ( DISTINCTCOUNT ( t2[Attribute] ) ) ),
ALLEXCEPT ( t2, t2[Group] )
)
nothing wrong with amitchandak 's solution. But for large tables I find ALLSELECTED not to be performant and I would only use that where it can't be avoided.
AlexisOlson
4 years agoSuper User
smpa01 Is there a reason for the iterators rather than writing this?
CALCULATE ( DISTINCTCOUNT ( t2[Attributes] ), ALLEXCEPT ( t2, t2[Group] ) )
- smpa014 years agoCommunity Champion
AlexisOlson great..skipped my mind.