Skip to main content
Community site session details

Community site session details

Session Id : vAyXjGrxTwiUnRNURkJyIp
Power Automate - Building Flows
Unanswered

Display ONLY duplicate values in array

Like (0) ShareShare
ReportReport
Posted on 16 Aug 2021 21:36:28 by 2

I am working on a project that requires filtering an array to show ONLY duplicate values. Take the below array for example:

 

[
 {
 "Name": "Customer Name",
 "ID": "TST1234",
 "Alt ID": "TST1234",
 "Bandwidth": "",
 "Location": "123 Somewhere Road",
 },
 {
 "Name": "Customer Name",
 "ID": "TST4567",
 "Alt ID": "TST1234",
 "Bandwidth": "",
 "Location": "555 Sunnylane Drive",
 },
 {
 "Name": "Customer Name",
 "ID": "TST5678",
 "Alt ID": "TST1234",
 "Bandwidth": "",
 "Location": "123 Somewhere Road",
 },
]

 

 

What I need is to filter the array to show duplicate 'Location' objects in the array while getting rid of the non duplicates. I want to have the following as the output. We need to strip the "555 Sunnylane Drive" value in the Location object since it's distinct.

 

[
 {
 "Name": "Customer Name",
 "ID": "TST1234",
 "Alt ID": "TST1234",
 "Bandwidth": "",
 "Location": "123 Somewhere Road",
 },
 {
 "Name": "Customer Name",
 "ID": "TST5678",
 "Alt ID": "TST1234",
 "Bandwidth": "",
 "Location": "123 Somewhere Road",
 },
]

 

 

From there, I need to add a condition to check if there are any values in the output of the above filter action. I need to check if there is any output because if we do, then we have duplicates and if we don't, well every value is distinct so there wont be any output.

 

Any ideas? I have a full working flow, but I want to to improve the flow to only show duplicate values in the array, not everything including distinct and duplicate objects.

  • takolota1 Profile Picture
    4,911 Moderator on 21 Jun 2022 at 05:22:12
    Re: Display ONLY duplicate values in array

    @DaftNewb @v-qiaqi-msft @kwalser 

     

    To give another update on an old topic, we should now be able to get only items that have at least 1 exact duplicate in an array pretty easily with some new expressions like nthindexof().

     

    We just need a Filter array with the From set to the outputs of a previous action, in this case I’ll use a Select action as some may want to find records that only duplicate a few of their columns, & they could use the Select action to select only a few columns to check..

     

    Expression…

    nthIndexOf(string(body(‘Select’)), string(item()), 2)

    with the Filter condition: is greater than

    -1

  • DaftNewb Profile Picture
    on 26 May 2022 at 19:39:24
    Re: Display ONLY duplicate values in array

    i don't know if it is unpolite to revive old topics here and this one probably don't need help anymore, but i since it is not answered this may be helpfull for other people also going through this problem. I was wanting the same thing and i found this video https://www.youtube.com/watch?v=LjDSnt8IBTA wich solved my problem.

  • kwalser Profile Picture
    2 on 17 Aug 2021 at 12:26:09
    Re: Display ONLY duplicate values in array

    Thank you, @v-qiaqi-msft! While this will work, the addresses are not explicit so this method wouldn't work between runs. I need to find a way to iterate through the array and ONLY keep duplicates no matter the location.

     

    There are also cases where there will be two or more duplicate Location values in the array which we would need to keep.

    [
     {
     "Name": "Customer Name",
     "ID": "TST1234",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "123 Somewhere Road",
     },
     {
     "Name": "Customer Name",
     "ID": "TST4567",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "555 Sunnylane Drive",
     },
     {
     "Name": "Customer Name",
     "ID": "TST5678",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "123 Somewhere Road",
     },
     {
     "Name": "Customer Name",
     "ID": "TST5678",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "456 Tree Lane",
     },
     {
     "Name": "Customer Name",
     "ID": "TST5678",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "456 Tree Lane",
     }
    ]

    In this case, we would only need to keep locations 123 Somewhere Road and 456 Tree Lane in the array while removing 555 Sunnylane Drive as Sunnylane doesn't have a duplicate location value whereas the others do. The new array should look like the following:

    [
     {
     "Name": "Customer Name",
     "ID": "TST1234",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "123 Somewhere Road",
     },
     {
     "Name": "Customer Name",
     "ID": "TST5678",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "123 Somewhere Road",
     },
     {
     "Name": "Customer Name",
     "ID": "TST5678",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "456 Tree Lane",
     },
     {
     "Name": "Customer Name",
     "ID": "TST5678",
     "Alt ID": "TST1234",
     "Bandwidth": "",
     "Location": "456 Tree Lane",
     }
    ]

    I have been playing around with different compose actions and filter arrays but cannot find a good way to achieve this. Hope this makes sense.

  • v-qiaqi@microsoft.com Profile Picture
    on 17 Aug 2021 at 07:18:53
    Re: Display ONLY duplicate values in array

    Hi @kwalser,

    Do you want to filter the duplicated array?

    Here is my complete flow configure:

    vqiaqimsft_5-1629184686266.png

    Here is the detailed steps"

    vqiaqimsft_0-1629184209374.png

    Write the expression within the first condition expression bar:

    item()?['Location']

    vqiaqimsft_3-1629184575111.png

    Or you could write the following expression within the advance mode

    @equals(item()?['Location'], '123 Somewhere Road')

    vqiaqimsft_4-1629184635781.png

    vqiaqimsft_2-1629184424046.png

     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2

Loading complete