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.

2 REPLIES 2
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.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (999)