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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Ant_BM
New Member

Distinct count based on all selected values

Hi all,

I have a Count problem that I can't seem to find an answer to. 

I have two tables Events and Event_Categories:

Event
ID
111
112
113
114

 

Event_categories
Event_IDCategory
111A
111B
112A
113B
114C


I also have a slicer with the category values.

I want to create a measure with the distinct count of Event_ID where the Event_ID is present for all selected Category values.

For example: if I select from my slicer the values A and B the distinct count should return 1 (as only Event_ID 111 matches on the selected values - if I selected only category value B it should return a distinct count of 2). 

I need the measure to also work on a table visual with the Event[ID] value, such as below for Category values A and B:

Event 
IDDistinct_count
1111
1120
1130
1140


Any suggestions on how I can create a measure with the expected output would be greatly appreciated. 

3 REPLIES 3
vk_pbi
Resolver II
Resolver II

Hi

Please try this below DAX

cnt = 
VAR _Combine =
CONCATENATEX(
    Event_categories,
    Event_categories[Event ID],","
)

VAR _CountRows= 
COUNTX(
    VALUES(Events[ID]),
    _Combine
)
RETURN
_CountRows

Hi vk_pbi,

Thank you for the reply.

I tried the DAX and it returns a distinct count where the category is A OR B whereas I'm hoping to return a count where Event_ID is present for all of the selected slicer values (i.e. A and B):

Ant_BM_1-1684994128796.png

In the above example the desired result would be 1

I think, i made it a bit complicated, but lets check it out 

cnt = 
VAR _NoofselectedValues = 
COUNTROWS(ALLSELECTED(Event_categories[Category]))

VAR _Combine =
CONCATENATEX(
    Event_categories,
    Event_categories[Event_ID],","
)
VAR _Combine_cat = 
CONCATENATEX(
    Event_categories,
    Event_categories[Category],","
)
VAR _CountRows= 
IF(
    NOT CONTAINSSTRING(
        MAX(Event_categories[Category]),
        _Combine_cat
    ),
    COUNTX(
        VALUES(Events[ID]),
        _Combine
    ),
    BLANK()
)
VAR _Result1 = 
IF(
    _NoofselectedValues >1,
    _CountRows,    
    COUNTX( VALUES(Events[ID]),_Combine)
)
RETURN
_Result1

 

vk_pbi_0-1684996574588.png

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.