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
DRing
Helper V
Helper V

"Total" Count of Duplicates

I am looking for a way to count the total numnber of duplicate records on a column. Using the sample data below for duplicate "Number", the expected output would be 6 =  4 for 001 + 2 for 003.

 

 Capture_2.PNG

2 ACCEPTED SOLUTIONS
vicky_
Super User
Super User

Try this formula:

Number of Duplicates = 
var summaryTable = ADDCOLUMNS(VALUES('Table'[Column1]), "duplicates", CALCULATE(COUNT('Table'[Column1])))
return SUMX(FILTER(summaryTable, [duplicates] > 1), [duplicates])

vicky__0-1694731889457.png

 

View solution in original post

If you want everything in one single measure, you can do as

Count Dups only Measure = SUMX( Filter( GROUPBY('Table', [Number], "Dups Cnt", COUNTX( CURRENTGROUP(), 1)), [Dups Cnt] > 1), [Dups Cnt]) 

 

You get the same output. I prefer two measure approach, as we can use "Cnts" for other places if needed.

 

🙂

View solution in original post

8 REPLIES 8
vicky_
Super User
Super User

Try this formula:

Number of Duplicates = 
var summaryTable = ADDCOLUMNS(VALUES('Table'[Column1]), "duplicates", CALCULATE(COUNT('Table'[Column1])))
return SUMX(FILTER(summaryTable, [duplicates] > 1), [duplicates])

vicky__0-1694731889457.png

 

@vicky_ Do you know how I can adjust this so that it returns "0" instead of "Blank" if the result is no duplicates?

Use COALESCE ...

 

Say, like this 

Count Dups only Measure 3 = COALESCE( SUMX( Filter( GROUPBY('Table', [Number], "Dups Cnt", COUNTX( CURRENTGROUP(), 1)), [Dups Cnt] > 1), [Dups Cnt]) , 0)

Worked perfectly. Thanks!

sevenhills
Super User
Super User

First of all your expected output is wrong! It should be 7

 

You can achieve this as two measure approach as below. hope it helps! 

 

First measure to count 

Cnts = count('Table'[Number])

 

Second measure to count duplicates

Count Dups only Measure = SUMX( FILTER ( DISTINCT ( 'Table'[Number] ), [Cnts] > 1 ), [Cnts] )

 

Sample output:

sevenhills_0-1694730816343.png

 

sevenhills_1-1694730846435.png

 

 

You're absolutely right. It should be 7. 🙄

Thanks!

If you want everything in one single measure, you can do as

Count Dups only Measure = SUMX( Filter( GROUPBY('Table', [Number], "Dups Cnt", COUNTX( CURRENTGROUP(), 1)), [Dups Cnt] > 1), [Dups Cnt]) 

 

You get the same output. I prefer two measure approach, as we can use "Cnts" for other places if needed.

 

🙂

Makes sense. Thanks!

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.