cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jkeckard007
Helper III
Helper III

comparing two Arrays Remove elements that are the same

I have two arrays

array 1 [apples, peas, pears, grapes],

array 2   [apples, oranges, bananas, peas, carrots]

If the item is in Array 1 my final array basically remove  any items it finds a match for from the final array

Final array [ oranges, bananas, carrots]

Can this be done in MS Flow?

1 ACCEPTED SOLUTION

Accepted Solutions
v-alzhan-msft
Community Support
Community Support

Hi @jkeckard007 ,

 

The array 1 and array 2 that you provided as below are not standard Array type:

array 1 [apples, peas, pears, grapes],

array 2   [apples, oranges, bananas, peas, carrots]

 

And the standard Array type array 1 and array 2 should as below:

["apples", "peas", "pears", "grapes"]
["apples", "oranges", "bananas", "peas", "carrots"]

 

 

Please refer to screenshot below to create the flow:

1.png2.png3.png4.png

 

The flow would run successfully as below:

5.png

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-alzhan-msft
Community Support
Community Support

Hi @jkeckard007 ,

 

The array 1 and array 2 that you provided as below are not standard Array type:

array 1 [apples, peas, pears, grapes],

array 2   [apples, oranges, bananas, peas, carrots]

 

And the standard Array type array 1 and array 2 should as below:

["apples", "peas", "pears", "grapes"]
["apples", "oranges", "bananas", "peas", "carrots"]

 

 

Please refer to screenshot below to create the flow:

1.png2.png3.png4.png

 

The flow would run successfully as below:

5.png

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@v-alzhan-msft 

Thanks for sharing this solution.

I have been struggling for a while to understand how something like this can be achieved in Power Automate.

 

I amended your solution to fit my scenario and thought that last "Set Variable2 - ExistinArray1 to False" would not be required but I don't get the right outcome without it. I don't understand why it is required.

If you can still remember why 😊 can you please explain why that last "Set Variable 2" to False is required in the Flow?

Thanks. 

 

The variable is set to false in the outer loop in preparation for the next run of the inner loop. If you don't reset it to false then any further run of the inner loop, after the first positive result, will be true no matter what the comparison result is.

Here's a way to achieve the same with a single loop 

https://powerusers.microsoft.com/t5/General-Power-Automate/get-differences-from-2-arrays/td-p/304051

@AlisterT 

The explanation for the nested loop though is equal parts clear as confusing 😊

Is the condition within the inner not already set to False in the first place? I.e. isn't that the condition that actually allows us to append "false" i.e. unmatching array values into the Final array in the first place?

It still seems to me that we are setting something to false that should already be false.

Would appreciate if you could clarify more, or provide a link to some "stuff" that can explain this set variable concept 🙏

 

Many thanks for the link you shared to the alternative approach. That was a lot easier for me to understand.

The condition within the inner loop is not setting the variable to false as far as I can see from his screenshots. The scope of the variable is the flow itself so once the inner loop sets it to true, after you make your comparison to check if the variable is false, you must set it back to false so it is not set to true when the inner loop runs again, if you don't then the flow will report a match when in fact there is none.

 

To be honest, I would have initialized the variable to false because it seems to me the check could fail if no match is found on the first run because the variable would still be null and not false.

@AlisterT 

Thanks for the responses and the suggestions.

The method has shed light on approaches I had not thought to do.

I will play with this approach and also try the alternative you pointed to. Lots to learn. 

Powerplatform01
Post Patron
Post Patron

@jkeckard007 

You can watch this video to resolve your issue.Also request you to please subscribe this channel

https://youtu.be/OIIjOy-p-UE

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,903)