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
kbandito
Frequent Visitor

[HELP] Distinct Count Measure with criteria, and responds to slicer selection

Hi, I have been trying to build a measure to distinct count Person with a certain criteria, and have that responding to a slicer that selects Place.

 

For example, I have a full table below ('ALL').

If i select Place AAA and BBB only using slicer, there is 9 total visits by 6 persons. Of this 6 persons, Person '1' has visited both places, while the remaining 5 persons have visited either one of AAA and BBB.

I want a measure that is able to distinct count people like Person '1'.

 

ALL

 

 

 SELECTION

 

Person 

Place

 

Person 

Place

1

AAA

 

1

AAA

1

BBB

 

1

BBB

1

CCC

 

1

BBB

1

DDD

 

2

AAA

2

AAA

 

2

AAA

2

CCC

 

3

BBB

3

BBB

 

4

AAA

3

CCC

 

5

BBB

3

DDD

 

7

AAA

2

AAA

 

 

 

1

BBB

 

 

 

4

AAA

 

 

 

5

BBB

 

 

 

6

CCC

 

 

 

7

AAA

 

 

 

 

1 ACCEPTED SOLUTION

Hey @kbandito ,

 

this measure

Measure = 
var _noofplaces = COUNTROWS(ALLSELECTED('Table'[Place]))
return
SUMX(
    VALUES('Table'[Person])
    , IF(CALCULATE(DISTINCTCOUNT('Table'[Place]), ALLSELECTED('Table'[Place])) >= _noofplaces , 1 , BLANK())
)

allows to create these visuals:

image.png

Hopefully, this is what you are looking for.

 

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey @kbandito ,

 

I'm not sure what the expected result should look like, but maybe this measure provides what you are looking for:

count distinct person = 
CALCULATE(
    DISTINCTCOUNT('Table'[Person])
    , ALLSELECTED('Table'[Person])
)

At least it allows to create visuals like below:

image.png

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens , thanks.

However, instead of a total count of person who have been to either one of the places, i want to only count person who have been to both places.

 

Hey @kbandito ,

 

this measure

Measure = 
var _noofplaces = COUNTROWS(ALLSELECTED('Table'[Place]))
return
SUMX(
    VALUES('Table'[Person])
    , IF(CALCULATE(DISTINCTCOUNT('Table'[Place]), ALLSELECTED('Table'[Place])) >= _noofplaces , 1 , BLANK())
)

allows to create these visuals:

image.png

Hopefully, this is what you are looking for.

 

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.