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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Search array for dupli...
Power Automate
Unanswered

Search array for duplicate substrings (email usernames) and remove without for each loop

(0) ShareShare
ReportReport
Posted on by 4

I have an array of emails, for example, ["user@mail.com", "user@differentmail.com"].

 

As you can see, the array has two emails that have the username "user" before the @ symbol. I need to remove duplicate emails in an array based username (everything before the @ symbol. Here, it is the string "user"). This is because I cannot guarantee that they have the same email domain ("mail" vs "differentmail"). I want to return an array with only one of the emails, where one of them is removed. In this example, the ideal return value would be either ["user@mail.com"] or ["user@differentmail.com"].

 

I would prefer this to be without a for each loop since I'm running this over about 14,000 lines. Thanks so much!

Categories:
  • SudeepGhatakNZ Profile Picture
    14,396 Most Valuable Professional on at

    @gbarnholtz 

    I don't know if it is possible to eliminate the loop completely, but the looping items can be reduced with the following approach. The flow below will return you the unique Usernames.

    You will then need to pick one email from the initial array where username matches the username in the last compose action. The last logic will require a loop but on a smaller subset because you are only dealing with the unique ones.

    SudeepGhatakNZ_0-1718152949759.png

     

    SudeepGhatakNZ_1-1718153071972.png

     

  • takolota1 Profile Picture
    4,980 Moderator on at

    @gbarnholtz 

    You could also use a Select to create a JSON array of objects using the array as the From input & with a username field of

    Split(item(), '@')[0]

    And an email field of

    item()


    Then you could use this template to with username as the DuplicateFieldCheck to process this to a JSON array of only distinct usernames & their associated emails

    https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Get-Distinct-Records-amp-Counts/td-p/2191533

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 302 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 263

#3
Henil Profile Picture

Henil 115

Last 30 days Overall leaderboard