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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
shankyy7227
Frequent Visitor

distinct count of multiple columns

My data contains FName, LName, MName, Gender, Card ID, Health ID, Active Flag and there may be Null in any column for each row i am trying to calculate distinct count  (FName+Card ID+Health ID) and distinct count  (FName+Card ID+Health ID+Where Gender=M)

FNAMELNAMEMNAMEGenderCard IDHealth IDActiveFlag
ABCDXM123456712345Y
BCEFYM981056167891N
ABCDXM123456712345Y
IHPQZM456789034564N
IMPYCF 56789N
   F145647867890N
MEEEBM 78901N
ABCDXM123456712345Y
BCEFYM981056167891N




Please help me with this.

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Create two measures and try the following Dax

 

Measure1 = COUNTROWS(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]))
Measure2 = COUNTROWS(FILTER(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]),User[Gender]="M"))

2018-06-06_9-32-30.png

 

 

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi,

I am wondering which is the best solution in terms of performance?

Concatenate Calculated Column ?
OR
GroupBy Measure ? 

Thank you in advance,

Rob

I think for performance is better calculated column, for datamodel size is better groupBy.

 

Correct me someone, if I am wrong.

marcorusso
Most Valuable Professional
Most Valuable Professional

Yes, calculated column is better for performance.

The measure will not perform well in that version, it's better to use SUMMARIZE instead of GROUPBY and CALCULATETABLE instead of FILTER, this way you don't have to materialize Gender:

Measure2 = 
CALCULATETABEL (
    COUNTROWS (
        SUMMARIZE ( User, User[FNAME], User[Card ID], User[Health ID] )
    ),
    User[Gender]="M"
)

 

Maestro!

Just a quick precision:

Measure2 = 
CALCULATE (
    COUNTROWS (
        SUMMARIZE ( User, User[FNAME], User[Card ID], User[Health ID] )
    ),
    User[Gender]="M"
)

 Change the CALCULATETABLE to simple  CALCULATE.

 

Have a great day!

Anonymous
Not applicable

Create two measures and try the following Dax

 

Measure1 = COUNTROWS(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]))
Measure2 = COUNTROWS(FILTER(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]),User[Gender]="M"))

2018-06-06_9-32-30.png

 

 

 

Anonymous
Not applicable

Worked for me too.

Thumbs up

Thanks Jessica the Measures are working.

Anonymous
Not applicable

Hi

 

1. Create a new column :   New_Col = 'Table1'[FNAME]&'Table1'[Card ID]&'Table1'[Health ID]

 

2. Then you can create measure to do the count as needed:

 

Dist_cnt = CALCULATE(DISTINCTCOUNT('Table1'[New_Col]))

 

Dist_Male_Cnt=CALCULATE(DISTINCTCOUNT('Table1'[New_Col]),'Table1'[Gender]="M")

 

Hope this helps.

 

Thanks
Raj

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.