Hello everyone,
I have two arrays of objects that I'm trying to compare. I only want to keep the records that are unique and write them to an excel table. I know how to write to an excel table so for time sake we can just add the unique values to a separate variable.
Below are images of the two separate arrays I want to compare both by "ID" and only keep the two records that are new. In this case it would be records with IDs 5 and 6.
Array1 Array2
Here is the code snippet with the two arrays as well:
Array1
[
{
"ID": 1,
"Status": "",
"Region": "NAMER",
"Program Name": "Fun Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 2,
"Status": "",
"Region": "NAMER",
"Program Name": "Fun Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 3,
"Status": "",
"Region": "NAMER",
"Program Name": "Long Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 4,
"Status": "",
"Region": "NAMER",
"Program Name": "Long Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 5,
"Status": "",
"Region": "NAMER",
"Program Name": "Hill Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 6,
"Status": "",
"Region": "NAMER",
"Program Name": "Hill Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
}
]
Array2
[
{
"ID": 1,
"Status": "",
"Region": "NAMER",
"Program Name": "Fun Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 2,
"Status": "",
"Region": "NAMER",
"Program Name": "Fun Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 3,
"Status": "",
"Region": "NAMER",
"Program Name": "Long Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
},
{
"ID": 4,
"Status": "",
"Region": "NAMER",
"Program Name": "Long Run",
"Tracked in MAP?": "Yes",
"Program Manager": "",
"Collaborator": ""
}
]
Any help that this forum can provide is greatly appreciated. I've been stuck on this forever! Also, relatively new to comparing arrays.
Best,
Daniel
This post should point you in the right direction
This post is specific to comparing arrays of objects
You can do it like this:
Blog: tachytelic.net
YouTube: https://www.youtube.com/c/PaulieM/videos
If I answered your question, please accept it as a solution 😘
Thank you @Paulie78 and @ScottShearer. So right now I have an "Apply to each" for my Array1 where I'm performing the following:
filter Array2 variables('Array2')['ID'] is not equal to item()['ID'].
(NOTE: New_Submits is Array1 and ExistingSessions is Array 2)
New_Submits=Array1 and ExistingSessions=Array2
However when I run my flow the filter fails with the following error message:
Any ideas why this is happening?
Also I should point out that my schema for both arrays are the same.
Why do you have the apply to each? You can copy what I did and you will get the result that you’re after.
Hey @Paulie78 I've tried just the filter without the Apply to each, one thing I noticed is that the filter is just checking to see if Array2 contains the current item but I need it to compare the property 'ID'. How would you update the filter to compare ID in both arrays?
User | Count |
---|---|
89 | |
40 | |
22 | |
20 | |
16 |
User | Count |
---|---|
136 | |
55 | |
47 | |
36 | |
25 |