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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
naseem_1973
Helper I
Helper I

Distinct count for two columns

Hi All,

 

I am a new user of Power BI. I have a table in which one primary column has a duplicate value. 

I have counted this column's distinct values. But how do I count other column values according to this column's unique values?

 

I have used below measuer but its not working.

 

CountOtherColumnByPrimary =
SUMX(
    VALUES(Demographic[MRN]),
    CALCULATE(
        COUNTROWS(Demographic),
        ALLEXCEPT(Demographic, Demographic[MRN])

 

MRN is primiray column.

 

naseem_1973_0-1693921791084.png

 

 

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Drag Gender to the Table visual and write this measure

Measure = distinctcount(Demographic[MRN])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yangliu-msft
Community Support
Community Support

Hi  @naseem_1973 ,

Do you mean counting by [MRN] and [Gender] grouping or do you mean counting the same number in the whole [Gender] based on the [Gender] of each [MRN].

 

The former:

Create measure.

Measure1 =
COUNTX(
  FILTER(ALL(Demographic),'Demographic'[MRN]=MAX('Demographic'[MRN])&&'Demographic'[Gender]=MAX('Demographic'[Gender])),[Gender])

Result:

vyangliumsft_0-1694141819918.png

The latter:

Create measure.

Measure2 =
var _select=SELECTCOLUMNS(FILTER(ALL(Demographic),'Demographic'[MRN]=MAX('Demographic'[MRN])),"column",[Gender])
return
COUNTX(
    FILTER(ALL(Demographic),
    'Demographic'[Gender] in _select&&'Demographic'[Gender]=MAX('Demographic'[Gender])),[Gender])

Result:

vyangliumsft_1-1694141819921.png

If that result does not meet your expectations, you can express the expected result in the form of a picture and we can help you better.

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Sir, 

I think you are not understand my query.

Mrn  Gender

123- Male

123  Male

211- Female

211-Femal

 

Keep in mind this scenario, I want to count 1 male and 1 female because both registrations same.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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