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
collis
Frequent Visitor

Count duplicates (checking multiple columns) and displaying count in new column

Hello all
I am working with data with duplicates; however, I can't remove them as I need to use other columns in other charts.
I would ideally like to create the below - where the first three columns are checked and, based on how many times they are or aren't duplicated, create a column with their counts. This will allow me to filter duplicates on the relevant charts. 

Note that I don't need to know if the duplicate is 2,3, etc. It could just be "first" and "duplicate"—whichever is easier. 

collis_0-1731628703608.png

Many thanks

Nicole

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @collis 

 

You can try the following methods. Start by adding the index column to the Power query.

vzhangtinmsft_0-1731655427923.png

Count =
CALCULATE ( COUNT ( 'Table'[Site] ),
    FILTER (
        ALLEXCEPT ('Table','Table'[Scheduled Start],'Table'[Scheduled End],'Table'[Site]),
        [Index] <= EARLIER ( 'Table'[Index] )
    )
)

vzhangtinmsft_1-1731655660012.png

Is this the result you were expecting?

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

10 REPLIES 10
Kedar_Pande
Super User
Super User

@collis 

Create a new column

Duplicate Status = 
VAR CurrentRowKey =
[Scheduled Start] & " " & [Scheduled End] & " " & [Site]
VAR RowCount =
CALCULATE(
COUNTROWS('YourTable'),
FILTER(
'YourTable',
'YourTable'[Scheduled Start] = EARLIER('YourTable'[Scheduled Start]) &&
'YourTable'[Scheduled End] = EARLIER('YourTable'[Scheduled End]) &&
'YourTable'[Site] = EARLIER('YourTable'[Site])
)
)
VAR RowNumber =
RANKX(
FILTER(
'YourTable',
'YourTable'[Scheduled Start] = EARLIER('YourTable'[Scheduled Start]) &&
'YourTable'[Scheduled End] = EARLIER('YourTable'[Scheduled End]) &&
'YourTable'[Site] = EARLIER('YourTable'[Site])
),
'YourTable'[Scheduled Start],
,
ASC,
Dense
)
RETURN
IF(RowNumber = 1, "First", "Duplicate")

Give this a try and let me know how it works for you!

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
Ashish_Mathur
Super User
Super User

Hi,

Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Scheduled StartScheduled EndSite
3/11/2023 9:003/11/2023 17:00NSW 
8/11/2023 9:008/11/2023 17:00NSW 
10/11/2023 9:3010/11/2023 10:30NSW 
10/11/2023 10:3010/11/2023 11:30NSW 
10/11/2023 10:3010/11/2023 11:30NSW 
13/11/2023 13:0013/11/2023 16:00NSW 
13/11/2023 13:3013/11/2023 21:30NSW 
14/11/2023 9:3014/11/2023 17:30NSW 
16/11/2023 9:0016/11/2023 17:00NSW 
16/11/2023 12:0016/11/2023 20:00NSW 
17/11/2023 11:3017/11/2023 19:30NSW 
22/11/2023 11:3022/11/2023 11:30NSW 
22/11/2023 11:3022/11/2023 19:30NSW 
23/11/2023 9:3023/11/2023 17:30NSW 
24/11/2023 9:0024/11/2023 17:00NSW 
24/11/2023 9:0024/11/2023 17:00NSW 
24/11/2023 9:0024/11/2023 17:00NSW 
24/11/2023 9:0024/11/2023 17:00NSW 
27/11/2023 11:0027/11/2023 14:00NSW 
29/11/2023 9:3029/11/2023 17:30NSW 
29/11/2023 9:3029/11/2023 17:30NSW 
29/11/2023 9:3029/11/2023 17:30NSW 
29/11/2023 10:0029/11/2023 18:00NSW 

 

Many thanks

Anonymous
Not applicable

Hi, @collis 

 

You can try the following methods. Start by adding the index column to the Power query.

vzhangtinmsft_0-1731655427923.png

Count =
CALCULATE ( COUNT ( 'Table'[Site] ),
    FILTER (
        ALLEXCEPT ('Table','Table'[Scheduled Start],'Table'[Scheduled End],'Table'[Site]),
        [Index] <= EARLIER ( 'Table'[Index] )
    )
)

vzhangtinmsft_1-1731655660012.png

Is this the result you were expecting?

 

Best Regards,

Community Support Team _Charlotte

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

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Scheduled Start", "Scheduled End", "Site"}, {{"Count", each Table.AddIndexColumn(_,"Index",1)}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Index"}, {"Index"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Count",{{"Scheduled Start", type datetime}, {"Scheduled End", type datetime}, {"Site", type text}, {"Index", Int64.Type}})
in
    #"Changed Type"

Hope this helps.

Ashish_Mathur_0-1731642582551.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you. So fast. This works well, but it deletes other columns. How would I keep other columns to be used for other charts?

collis
Frequent Visitor

Thank you again for the reply. Unfortunately, my knowledge isn't advanced enough.  Trying though... If I list all the columns, the count won't work as the data in the other columns isn't duplicated. I only need to check duplicates across three columns, and then the other columns I need to keep to be able to do other charts. I have seen people add 

{"all", each _, type table [membercode=number, capacity=number]}

but I can't get it to work.  Sorry, this is really stretching my brain!

You are welcome.  In the Grouped Rows step, mention all the columns.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
collis
Frequent Visitor

Sorry - I just quickly put together a demonstration to help communicate (and keep the data private). Imagine they are duplicates.

PhilipTreacy
Super User
Super User

@collis 

 

Hi Nicole,

 

The last 3 rows in your image aren't duplicates because the time in the Scheduled End column are different?

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.