cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kwalser
Regular Visitor

Display ONLY duplicate values in array

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.

4 REPLIES 4
v-qiaqi-msft
Community Support
Community Support

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

 

Best Regards,
Qi
kwalser
Regular Visitor

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.

DaftNewb
Helper I
Helper I

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.

@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

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (2,315)