Forum Discussion
COUNTDISTINCT vs COUNT for coverage calculations
[Client Coverage] =
// If more than 1 product is visible
// in the current context it returns
// the minimum coverage among all the
// visible products. So, if 1 product
// is visible, it agrees with your
// definition. If you want this measure
// to return BLANK if many products are
// visible/selected, put the body in
// IF( HASONEVALUE( T[Product] ),...
var AllClientCount =
CALCULATE(
DISTINCTCOUNT( T[Client] ),
ALL( T )
)
var Result =
DIVIDE(
MINX(
DISTINCT( T[Product] ),
CALCULATE( DISTINCTCOUNT( T[Client] ) )
),
AllClientCount
)
return
Result
- megane1235 years agoFrequent Visitor
Good morning Daxer,
Thanks for this! I noticed you replied to my colleague's post with the same query - I had a few questions on your response, hoping you can help:
- You have declared AllClientCount but I don't see it used anywhere else in the measure, is this intentional?
- The variable VisibleClientCount isn't declared so will error when trying to run this.
- When you say 'put the body in', where do you mean I should include this in the measure?
Thanks v much in advance for your help!
- Anonymous5 years agoNot applicable
Of course there's a mistake in the code but it's obvious: change the name of the variable that does not exist to the one that does. The above formula is one way to solve the problem. Another one is in the other post you mention.
"Put the body in..." means that the whole body of the measure should be wrapped in "IF(..."