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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
gowtham1991
Frequent Visitor

DistinctCount not showing the correct numbers

Dear Together,
I am facing an issues while using disctinct count in the Dax column.

Issue description:

I have two tabled A and B as below , with relationship many to many.

Table A 
IDData
12A
13B
14C

 

Table B 
CustIDID
AA12
AB13
AC12
AD12
AA12

 

I am creatting a DAX custom column using query Calculate(distinctCount(TableA[ID])) to bring the expected result as below

Expected Results  
IDDataCount of CUST ID (DAX Column)
12A3
13B1
14C

 

 

But I am not getting the correct numbers as expected and result comes as below

Actual  Results  
IDDataCount of CUST ID (DAX Column)
12A1
13B1
14C 

 

Not sure what is wrong with relation or query, 

 

Thanks

Gowtham

8 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@gowtham1991 That looks correct to me, you have 1 12 (A), 1 13 (B) in Table A. You have no 14 in Table B. Is your measure supposed to count TableB or TableA because you are saying it is counting TableA which seems wrong. Plus, would you want to be counting TableB[CustID] because those are the distinct values AA, AC, AD for 12 for example but you are saying you are counting TableA[ID] which doesn't make sense.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Bibiano_Geraldo
Super User
Super User

hI @gowtham1991 ,

In your table A, create a new calculated column by this DAX:

Count of CUST ID = 
CALCULATE(
    DISTINCTCOUNT('Table B'[CustID]),
    FILTER(
        'Table B',
        'Table B'[ID] = 'Table A'[ID]
    )
)

Your output should look like this:

Bibiano_Geraldo_0-1739462109750.png

 

View solution in original post

hello @Greg_Deckler 

 

thanks for your replay, The query used is  Calculate(distinctCount(TableB[ID])). Still with this query I am facing the same issue.

View solution in original post

@Bibiano_Geraldo  Thanks you for your replay, Unfortunately this does not solve the issue. Note:, Not all the values are wrong, I have only few rows showing a incorrect date. 

In the acatual fileI have atmost 300K rows and nealy 100+ rows showing incrrect values a

View solution in original post

Hi @gowtham1991 ,

A many-to-many relationship can cause issues with DISTINCTCOUNT calculations. A better approach is to create a bridge table to normalize the relationship between Table A and Table B.

You need a unique list of ID values to act as a bridge:

BridgeTable = DISTINCT(UNION(SELECTCOLUMNS('Table A', "ID", 'Table A'[ID]), SELECTCOLUMNS('Table B', "ID", 'Table B'[ID])))

Set Up Relationships:
Relate BridgeTable[ID] one-to-many with Table A[ID].
Relate BridgeTable[ID] one-to-many with Table B[ID]. 

 

Now, use this measure to get the distinct count of CustID dynamically:

Count of CUST ID = 
CALCULATE(
    DISTINCTCOUNT('Table B'[CustID]),
    RELATEDTABLE('Table B')
)

View solution in original post

Anonymous
Not applicable

Hi, @gowtham1991 

Thanks for the reply from Bibiano_Geraldo and Greg_Deckler. You can refer to their suggestions, or you can refer to the following ways to achieve your need.

Relationship: Many to many, single A to B.

vyaningymsft_1-1739502542247.png


Method 1:
Add the filed, and change the filed of CustID to Count of CustID.

 

 

 

vyaningymsft_2-1739502629746.png


Method 2:
Use this measure.

Measure Count of CustID = CALCULATE(DISTINCTCOUNT('Table B'[CustID]))

 

vyaningymsft_0-1739502805038.png

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

hello @Anonymous 

 

Thanks for your suggestions, unfortunatly I have to user this as a column, as I have a another custom column getting created using the values form this column.

View solution in original post

Anonymous
Not applicable

Hi, @gowtham1991 

Bibiano_Geraldo also gave a good advice, you can check it. The formula works fine with less amount of data, not sure what is the issue on your end, you can share the pbix file you expect to realize the output and share it without sensitive data for testing.

vyaningymsft_0-1739771968977.png

 

Best Regards,
Yang

Community Support Team

View solution in original post

9 REPLIES 9
gowtham1991
Frequent Visitor

@Anonymous @Bibiano_Geraldo @Greg_Deckler 

Dear Experts, With all the suggestions, Created the measure and called the measure as a column required table and this solved the issue

 

Thanks

Gowtham

Anonymous
Not applicable

Hi, @gowtham1991 

Thanks for the reply from Bibiano_Geraldo and Greg_Deckler. You can refer to their suggestions, or you can refer to the following ways to achieve your need.

Relationship: Many to many, single A to B.

vyaningymsft_1-1739502542247.png


Method 1:
Add the filed, and change the filed of CustID to Count of CustID.

 

 

 

vyaningymsft_2-1739502629746.png


Method 2:
Use this measure.

Measure Count of CustID = CALCULATE(DISTINCTCOUNT('Table B'[CustID]))

 

vyaningymsft_0-1739502805038.png

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

hello @Anonymous 

 

Thanks for your suggestions, unfortunatly I have to user this as a column, as I have a another custom column getting created using the values form this column.

Anonymous
Not applicable

Hi, @gowtham1991 

Bibiano_Geraldo also gave a good advice, you can check it. The formula works fine with less amount of data, not sure what is the issue on your end, you can share the pbix file you expect to realize the output and share it without sensitive data for testing.

vyaningymsft_0-1739771968977.png

 

Best Regards,
Yang

Community Support Team

Bibiano_Geraldo
Super User
Super User

hI @gowtham1991 ,

In your table A, create a new calculated column by this DAX:

Count of CUST ID = 
CALCULATE(
    DISTINCTCOUNT('Table B'[CustID]),
    FILTER(
        'Table B',
        'Table B'[ID] = 'Table A'[ID]
    )
)

Your output should look like this:

Bibiano_Geraldo_0-1739462109750.png

 

@Bibiano_Geraldo  Thanks you for your replay, Unfortunately this does not solve the issue. Note:, Not all the values are wrong, I have only few rows showing a incorrect date. 

In the acatual fileI have atmost 300K rows and nealy 100+ rows showing incrrect values a

Hi @gowtham1991 ,

A many-to-many relationship can cause issues with DISTINCTCOUNT calculations. A better approach is to create a bridge table to normalize the relationship between Table A and Table B.

You need a unique list of ID values to act as a bridge:

BridgeTable = DISTINCT(UNION(SELECTCOLUMNS('Table A', "ID", 'Table A'[ID]), SELECTCOLUMNS('Table B', "ID", 'Table B'[ID])))

Set Up Relationships:
Relate BridgeTable[ID] one-to-many with Table A[ID].
Relate BridgeTable[ID] one-to-many with Table B[ID]. 

 

Now, use this measure to get the distinct count of CustID dynamically:

Count of CUST ID = 
CALCULATE(
    DISTINCTCOUNT('Table B'[CustID]),
    RELATEDTABLE('Table B')
)
Greg_Deckler
Super User
Super User

@gowtham1991 That looks correct to me, you have 1 12 (A), 1 13 (B) in Table A. You have no 14 in Table B. Is your measure supposed to count TableB or TableA because you are saying it is counting TableA which seems wrong. Plus, would you want to be counting TableB[CustID] because those are the distinct values AA, AC, AD for 12 for example but you are saying you are counting TableA[ID] which doesn't make sense.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

hello @Greg_Deckler 

 

thanks for your replay, The query used is  Calculate(distinctCount(TableB[ID])). Still with this query I am facing the same issue.

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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