Forum Discussion

Mansfig2's avatar
Mansfig2
New Member
4 years ago
Solved

Count Distinct with condition across partition

Hey guys,

 

I'm struggling to find a DAX based solution to this problem I'm having, this is the table I have:

 

 

How would I count the number of distinct values within column 2, grouping within the ID in the first column?

 

The count should look something like this: 


Thanks for the help! 

 

George

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Mansfig2 ,

    You can create a calculated column as below:

    CountDistinct = 
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID2] ),
        FILTER ( 'Table', 'Table'[ID1] = EARLIER ( 'Table'[ID1] ) )
    )

    Best Regards

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Mansfig2 ,

    You can create a calculated column as below:

    CountDistinct = 
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID2] ),
        FILTER ( 'Table', 'Table'[ID1] = EARLIER ( 'Table'[ID1] ) )
    )

    Best Regards