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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Composite Key - Duplicates

Hi All,

 

I have the following table :

 

IDCodeDateComposite
1282014.07.2024 
2129201.06.2024 
3586901.01.2024 
4291020.11.2024 
5293922.06.2024 
5458019.10.2024 
6302015.07.2024 
6101825.10.2024 
6302015.07.2024 
7184602.03.2024 
8108407.03.2024 
9375011.09.2024 
10495012.03.2024 
10495012.03.2024 

 

I also have a composite key with the following measure :

 

[ID] & " | " & [Code] & " | " & [Date]
 
Now I want to count only the duplicates :
 
Ex : 6 and 10 IDs are exact duplicates as the composite key is a match.
 
GallopPBI_0-1726069693445.png

 

 
How can I achieve this in PBI? Thanks
1 ACCEPTED SOLUTION
samratpbi
Super User
Super User

Hi,

 

If you want to count the duplicates, then you can use the below measures to achieve that.

First, create a measure to count total rows in the table:

Total Count = COUNTROWS(Composite_Count)
Then create a measure to count unique rows based on composite key column you have created:
Unique Count = DISTINCTCOUNTNOBLANK(Composite_Count[Composite])
Then measure 1 - measure 2 will give you duplicate count:
Duplicate Count = [Total Count] - [Unique Count]
 
If this helps to resolve your problem, then mark this as solution provide, thanks!

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

@samratpbi Thank you, however the results are not exactly correct and it is due to the date column

 

GallopPBI_0-1726142073377.png

 

It is not considering date in the key. Please advise. Thanks

Anonymous
Not applicable

Hi @Anonymous 

 

Please correct me if I've misunderstood.

In my understanding, samratpbi's method should be correct. Only composite key matches exactly will be counted, in your screenshot the two rows don't match exactly because of the different dates, so Date “22.05.2024” has a duplicate count of 0, while Date “10.04.2024 has a duplicate count of 1, which should be a duplicate of the original data. 

 

Based on the example data you provided, using samratpbi's method, the test results look correct.

The measures created are as follows:

CompositeKey = [ID] & " | " & [Code] & " | " & [Date]
CountAllRows = COUNTROWS('Table')
CountDistinctRows = DISTINCTCOUNTNOBLANK('Table'[CompositeKey])
DuplicateRowsCount = [CountAllRows] - [CountDistinctRows]

 

vxianjtanmsft_0-1726645649847.pngvxianjtanmsft_1-1726645669431.png

 

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

 

 

mickey64
Super User
Super User

Step 1: I add a column.

mickey64_0-1726070814516.png

 

Step 2: I make a matrix.

mickey64_1-1726070858156.png

 

samratpbi
Super User
Super User

Hi,

 

If you want to count the duplicates, then you can use the below measures to achieve that.

First, create a measure to count total rows in the table:

Total Count = COUNTROWS(Composite_Count)
Then create a measure to count unique rows based on composite key column you have created:
Unique Count = DISTINCTCOUNTNOBLANK(Composite_Count[Composite])
Then measure 1 - measure 2 will give you duplicate count:
Duplicate Count = [Total Count] - [Unique Count]
 
If this helps to resolve your problem, then mark this as solution provide, thanks!
Anonymous
Not applicable

@samratpbi Thanks actually the COUNTROWS on composite keys does not work

GallopPBI_0-1726070911092.png

 

Can you please help..Thanks

 

Hi, Countrows works on table, not column. Hence please provide the table name, it should return total count in that table.

 

If this helps to resolve your problem, then mark it as solution, thanks!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.