web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Count Number of Duplic...
Power Apps
Unanswered

Count Number of Duplicates in Collection

(0) ShareShare
ReportReport
Posted on by 1,387 Moderator

I have a collection of numbers that get scanned in. A Gallery is populated with those values and indicate if a given record, is a duplicate. I'd like to have a running count for how many duplicates there are. I'm not sure how to accomplish this.

Categories:
I have the same question (0)
  • AndrewR1 Profile Picture
    1,572 Moderator on at

    Hi  @IPC_ahaas here is how I manged to do this:

     

    So firstly I have an Ice cream list and I want to check if it has duplicate flavours so I do:

     

    Clear(Duplicates);
    ForAll(
     IceCream As Item,
     If(
     CountRows(
     Filter(
     IceCream,
     Flavor = Item.Flavor
     )
     ) > 1,
     Collect(
     Duplicates,
     Item
     )
     )
    )
    

     

    This the give me a list like so:

    AndrewR1_0-1711119851233.png

    Then I do this to see how many instances of duplicate records I have: 

     

    CountRows(Duplicates)

     

    This then will return me the value of 2 duplicate records Not sure if there is a different way to achieve this! But I hope this helps!

    Please click Accept as solution if my post helped you solve your issue. ✔️ This will help others find the solution to this problem. It also closes the item. Remember, you can accept more than one post as a solution.

    If the content was useful in other ways, please consider giving it Thumbs Up. 👍

    Thanks
    Andrew

     

     

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @IPC_ahaas 

    As an example,  let's take this collection with 3 duplicate records:

    ClearCollect(
     colBarcodes,
     {Barcode: "1234567890", Description: "Item 1"},
     {Barcode: "2345678901", Description: "Item 2"},
     {Barcode: "3456789012", Description: "Item 3"},
     {Barcode: "4567890123", Description: "Item 4"},
     {Barcode: "5678901234", Description: "Item 5"},
     {Barcode: "6789012345", Description: "Item 6"},
     {Barcode: "7890123456", Description: "Item 7"},
     {Barcode: "1234567890", Description: "Item 1"}, // Duplicate
     {Barcode: "2345678901", Description: "Item 2"}, // Duplicate
     {Barcode: "3456789012", Description: "Item 3"} // Duplicate
    )

     

    The following formula will return a count of 3

    CountIf(AddColumns(
     GroupBy(colBarcodes,
     "Barcode",
     "Items"
     ),
     "BarcodeCount",
     CountRows(Items)
    ) ,BarcodeCount>1)
    
  • IPC_ahaas Profile Picture
    1,387 Moderator on at

    This works great, but is there a way to get the number of reoccurrences? Like if one value shows up three times?

  • IPC_ahaas Profile Picture
    1,387 Moderator on at

    I'm getting an error on the "Item" portion.

     

    My existing Collection is "ColBundles" and I want to find duplicates for the value "BundleTag", so this is what I have:

     

    Clear(ColDuplicateBundles);
    ForAll(
     ColBundles,
     If(
     CountRows(
     Filter(
     ColBundles,
     BundleTag = Item.BundleTag
     )
     ) > 1,
     Collect(
     ColDuplicateBundles,
     BundleTag
     )
     )
    );

     

    I put this on a button so it'll run with each new addition. The code doesn't like the "Item.BundleTag"

     

    IPC_ahaas_0-1711128055122.png

     

  • Verified answer
    AndrewR1 Profile Picture
    1,572 Moderator on at

    Hi @IPC_ahaas you just missed off the 'As Item' in the For all function: 

     

    Clear(ColDuplicateBundles);
    ForAll(
     ColBundles As Item,
     If(
     CountRows(
     Filter(
     ColBundles,
     BundleTag = Item.BundleTag
     )
     ) > 1,
     Collect(
     ColDuplicateBundles,
     BundleTag
     )
     )
    );

     Please click Accept as solution if my post helped you solve your issue. ✔️ This will help others find the solution to this problem. It also closes the item. Remember, you can accept more than one post as a solution.

    If the content was useful in other ways, please consider giving it Thumbs Up. 👍

    Thanks
    Andrew

  • IPC_ahaas Profile Picture
    1,387 Moderator on at

    Now it tells me "Name isn't valid. 'BundleTag' isn't recognized."

     

    IPC_ahaas_1-1711371032149.png

     

  • IPC_ahaas Profile Picture
    1,387 Moderator on at

    I think this is because I'm putting it on the same button that adds items to ColBundles. So it doesn't exist yet and it's trying to quantify it.

     

    IPC_ahaas_3-1711371318349.png

     

     

  • Verified answer
    IPC_ahaas Profile Picture
    1,387 Moderator on at

    I got this working. I had to change the last portion:

     

    Collect(
     ColDuplicateBundles,
     BundleTag
    )

     

    to

     

    Collect(
     ColDuplicateBundles,
     VarAddBundleTagBundles
    )

     

    This way it uses the same variable to for ColDuplicateBundles at it does ColBundles, at the time of creation.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard