Forum Discussion

MEHUL123's avatar
MEHUL123
Frequent Visitor
1 year ago
Solved

Conditional distinct count dax

Hi,

 

Request your help to create DAX for Distinct count of IDs against each Name rows in table.

(desired result shown in last colunms)

 

NameID NO.DAX for Desired Result
(Distinct ID against Name)
RohanAA2
RohanBB2
RohanAA2
MiraBB2
JohnAA1
MiraCC2
CelvinAA1
JamesAA1
CelvinAA1

 

Thanks in advance..

  • MEHUL123 Try this. PBIX is attached below signature.

    Distinct Count = 
        VAR __Name = MAX( 'Table'[Name] )
        VAR __Table = FILTER( ALLSELECTED( 'Table' ), 'Table'[Name] = __Name )
        VAR __Group = SUMMARIZE( __Table, [Name], [ID] )
        VAR __Result = COUNTROWS( __Group )
    RETURN
        __Result

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    MEHUL123 Try this. PBIX is attached below signature.

    Distinct Count = 
        VAR __Name = MAX( 'Table'[Name] )
        VAR __Table = FILTER( ALLSELECTED( 'Table' ), 'Table'[Name] = __Name )
        VAR __Group = SUMMARIZE( __Table, [Name], [ID] )
        VAR __Result = COUNTROWS( __Group )
    RETURN
        __Result
  • MEHUL123 

    DAX measure:

    Distinct ID Count = 
    CALCULATE(
    DISTINCTCOUNT(Table[ID NO.]),
    ALLEXCEPT(Table, Table[Name])
    )

    This will give you the distinct count of ID NO. for each Name.

     

     

    If this helped, a Kudos 👍 or Solution mark would be great!🎉
    Cheers,
    Kedar Pande
    Connect on LinkedIn