Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
megane123
Frequent Visitor

Client Coverage Measures - not interacting with filters properly

Hi all,

 

I am having a bit of trouble trying to get filters to properly affect visuals involving coverage measures, specifically the 'Top N' filter and general page slicers.

 

I am using the below measure to calculate how many distinct clients have purchased a specific product, divided by the total number of distinct clients (167 in this case), resulting in the coverage (%) for each particular product: 

 

Client Coverage  =
var TotalClientCount =
    CALCULATE(
        DISTINCTCOUNT( SalesTable[ClientKey] ),
        ALL( SalesTable )
    )
var Result =
    AVERAGEX(
        DISTINCT( SalesTable[ProductKey] ),
        CALCULATE( DISTINCTCOUNT( SalesTable[ClientKey] ) )
            / TotalClientCount
    )
return
    Result

 

This works well when no filters are applied to any of the visuals using the measure, resulting in the following correct results (displayed as a barchart in my dashboard):

 

ProductDistinct Client CountClient Coverage
A13078%
B7143%
C9557%
D5634%
....
X9456%
Y2616%
Z6740%
Total Distinct Client Count167 

 

However, my first issue is when I apply the Top 5 Products (by Client Coverage %) filter to a visual, it skews the total to only look at clients which have ever purchased any of the top 5 products listed (150 in this case), looking like the following (again, displayed by a barchart in my dashboard):

 

 

ProductDistinct Client CountClient Coverage
A13087%
B7147%
C9563%
X9463%
Z6745%
Total Distinct Client Count150 

 

In this scenario, I need the Total distinct Client Count to remain at 167, so that the Client Coverages remain as they did in the first table, before the Top N filter is applied.

 

My second issue is when I try to filter this visual by another column in the dataset (using a slicer), the total Distinct Client Count remains as the actual overall total client count (167), where I need it to be relative to that filter. For example, we have a total of 4 clients in the retail intustry, 3 of which have purchased product A. I would like to show a Client Coverage here of 75% (3/4), but this measure is resulting in a a Client Coverage of 2% (3/167). 

 

Is there a way to force the measure to display these different filters in the way I have explained? 

 

Thank you so much in advance for your help!

3 REPLIES 3
Anonymous
Not applicable

@megane123 

 

Did my previous post help you achieve what you wanted? If so, please mark it as THE solution. Thanks.

Anonymous
Not applicable

Update you measure to this:

 

[Client Coverage (absolute)] =
var AbsoluteTotalClientCount =
	// Since Clients is a dimension
	// table, each row represents a
	// different client, therefore
	// countrows will return the
	// number of all clients in the
	// system. I assume there are no
	// referential integrity problems
	// in the model. Otherwise, this
	// could return a wrong number.
    CALCULATE(
        COUNTROWS( Clients ),
        ALL( Clients )
    )
var Result =
    AVERAGEX(
        DISTINCT( SalesTable[ProductKey] ),
        CALCULATE(
        	DISTINCTCOUNT( SalesTable[ClientKey] ) 
        		/ AbsoluteTotalClientCount
        )
    )
return
    Result

 

Writing DAX measures without the model in sight and without a precise definition is more than hard. When askingfor help, you should always give us all the details.

 

"In this scenario, I need the Total distinct Client Count to remain at 167, so that the Client Coverages remain as they did in the first table, before the Top N filter is applied."

 

The above measure will return the absulute coverage but the total SHOULD be what it shows. It shows you the correct number of clients based on the filter. If you want to have a measure that willl always display the total number of clients in your system, you should use a different measure:

 

[# Clients (absolute)] =
    CALCULATE(
        COUNTROWS( Clients ),
        ALL( Clients )
    )

 

"My second issue is when I try to filter this visual by another column in the dataset (using a slicer), the total Distinct Client Count remains as the actual overall total client count (167), where I need it to be relative to that filter. For example, we have a total of 4 clients in the retail intustry, 3 of which have purchased product A. I would like to show a Client Coverage here of 75% (3/4), but this measure is resulting in a a Client Coverage of 2% (3/167)."

 

You're talking here about a completely different measure - a relative measure. A measure like this would be:

 

[Client Coverage (relative)] =
var RelativeTotalClientCount =
	// Since Clients is a dimension
	// table, each row represents a
	// different client, therefore
	// countrows will return the
	// number of all clients in the
	// system. I assume there are no
	// referential integrity problems
	// in the model. Otherwise, this
	// could return a wrong number.
    COUNTROWS( Clients )
var Result =
    AVERAGEX(
        DISTINCT( SalesTable[ProductKey] ),
        CALCULATE(
        	DISTINCTCOUNT( SalesTable[ClientKey] ) 
        		/ RelativeTotalClientCount
        )
    )
return
    Result

 

Also, it's of utmost importance to understand that you should never slice data by fields in your fact table. Only by what's in dimensions. If you don't obey this rule, you'll be in trouble.

 

 

amitchandak
Super User
Super User

@megane123 , if yoi want filter to work try allselected

 

Client Coverage =
var TotalClientCount =
CALCULATE(
DISTINCTCOUNT( SalesTable[ClientKey] ),
ALLSELECTED( SalesTable )
)
var Result =
AVERAGEX(
DISTINCT( SalesTable[ProductKey] ),
CALCULATE( DISTINCTCOUNT( SalesTable[ClientKey] ) )
/ TotalClientCount
)
return
Result

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors