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
Community Support
Community Support

Re: comparing two Arrays Remove elements that are the same

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

6 REPLIES 6
Community Support
Community Support

Re: comparing two Arrays Remove elements that are the same

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

mo_jo_jo
Frequent Visitor

Re: comparing two Arrays Remove elements that are the same

@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. 

 

AlisterT Helper I
Helper I

Re: comparing two Arrays Remove elements that are the same

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

mo_jo_jo
Frequent Visitor

Re: comparing two Arrays Remove elements that are the same

@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.

AlisterT Helper I
Helper I

Re: comparing two Arrays Remove elements that are the same

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.

Highlighted
mo_jo_jo
Frequent Visitor

Re: comparing two Arrays Remove elements that are the same

@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. 

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (6,097)