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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
shoemaker27
Frequent Visitor

Count Distinct Measure at lowest level

Hi!, Im struggling with this measure, Im not getting the result I want, I have this table:

sale_idsale_typeperson
11a
21b
32c
42x
52y
62z
73a

 

I want a measure that calculates the distinct count of person for each sale_type, the result should be like this:

 

sale_idsale_typepersonDistinct_Person_Per_Sale_Type
11a2
21b2
32c4
42x4
52y4
62z4
73a1

 

This measure works but only If I not add the sale_id to the table:

 

Distinct_Person_Per_Sale_Type = CALCULATE(
    DISTINCTCOUNT('Table'[person]), ALLEXCEPT('Table','Table'[sale_id],'Table'[sale_type])
    )
 
How can I achieve that the measure works at the lowest level of the table (sale_id)?
 
thanks a lot for your guidance and help!
 
2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @shoemaker27 
Pleas try

Distinct_Person_Per_Sale_Type =
COUNTROWS (
    CALCULATETABLE (
        VALUES ( 'Table'[person] ),
        ALL ( 'Table' ),
        -- can use ALLEXCEPT and include filter safe columns if any
        VALUES ( 'Table'[sale_type] )
    )
)

View solution in original post

@shoemaker27 

Please try

Distinct_Person_Per_Sale_Type =
COUNTROWS (
CALCULATETABLE (
VALUES ( 'Table'[person] ),
ALLSELECTED ( 'Table' ),
VALUES ( 'Table'[sale_type] )
)
)

View solution in original post

7 REPLIES 7
shoemaker27
Frequent Visitor

excellent!! one more workaround, the person dimension:

personkind
adirector
bmanager
cmanager
xmanager
ydirector
zmanager

 

If I put an slicer for "Kind", the count returns the same result, and should be the distinct count of person but for the kind selected, I added "kind" to the allexcept but the numbers dont change!

any workaround for this!

thanks a lot! @tamerj1 

 

@shoemaker27 
Please share some details about your data model

The model is like this:

shoemaker27_0-1680012687470.png

 

@shoemaker27 

Please try

Distinct_Person_Per_Sale_Type =
COUNTROWS (
CALCULATETABLE (
VALUES ( 'Table'[person] ),
ALLSELECTED ( 'Table' ),
VALUES ( 'Table'[sale_type] )
)
)

Awesome!! thanks!!!

Still trying to understand how works the filter VALUES ( 'Table'[sale_type] ) on the context.

@shoemaker27 
ALLSELECTED removes all inner filters imposed byu the visual itself but keeps the outer filters imposed by slicers, page filters and visual level filters. VALUES restores the filter of sales_type

tamerj1
Super User
Super User

Hi @shoemaker27 
Pleas try

Distinct_Person_Per_Sale_Type =
COUNTROWS (
    CALCULATETABLE (
        VALUES ( 'Table'[person] ),
        ALL ( 'Table' ),
        -- can use ALLEXCEPT and include filter safe columns if any
        VALUES ( 'Table'[sale_type] )
    )
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.