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.
@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
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.
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.
Hi @kwalser,
Do you want to filter the duplicated array?
Here is my complete flow configure:
Here is the detailed steps"
Write the expression within the first condition expression bar:
item()?['Location']
Or you could write the following expression within the advance mode
@equals(item()?['Location'], '123 Somewhere Road')
Tomac
986
Moderator
stampcoin
699
Super User 2025 Season 2
Riyaz_riz11
577
Super User 2025 Season 2