Comparing two arrays without an apply to each?

Published Feb 14 2022 04:56 AM 2,755 Views
Senior Member

The two arrays

I have two arrays in Power Automate, whilst very similar in structure (key/value pairs) the unique ID for both arrays is named differently (id vs PersonId) but I want to compare both and return only those that do not appear in the Array 1.  We can see from the image below that object id 3 & 4 are not present in Array 2.

 

DamoBird365_0-1644836389622.png

 

Using an Apply to Each

The most common method for comparing these two arrays will involve using an apply to each, maybe even nested apply to each actions.  This results in a very inefficient flow.  It will use up far more api calls than are required and result in your flow taking a lot longer to run.  You might even require a variable to append each object during the loop and a final compose to output the contents of the new variable. 

 

DamoBird365_1-1644837296978.png

 

Above is an example of an apply to each solution that when run on the two original arrays, takes 2 seconds to complete on 5 records!

 

Using Select and Filter Array Actions

 

Using Select to establish an array of PersonID's

 

First, I want to establish an array of PersonID's, as I will use this to check if the ID of the first array appears in the Array of PersonID's. This can be done using a select action in text mode, by clicking on the icon on Select (bottom right hand corner).

 

DamoBird365_2-1644837637842.png

 

The output of which demonstrates how we have converted our 2nd Array into an array of ID's.

 

DamoBird365_3-1644837759026.png

 

Using Filter Array to establish missing objects

 

With Array 1 as the input to our filter array action, we can check if the id item()?['id'] of each object is not contained (does not contain) within the array of PersonID's we have created using the select previously body('select').  This is all achieved using a single action and will run on large datasets in a fraction of a second, using only the single api call.

 

DamoBird365_5-1644838204804.png

 

Below we can see the input of Array 1, with the history output showing only id's 3 & 4 being returned.

 

DamoBird365_4-1644837898424.png

 

Finally, if your requirement is to get an array of id's that are contained within both arrays, i.e. object ID's 1, 2 and 5, you can simply change the expression to contains.

 

DamoBird365_7-1644838602675.png

Running this on Larger Data Sets?

Below you will see the flow having run on 100 records in an array.  The Select/Filter method has completed in 0 seconds once more, but the apply to each has taken 40 seconds and whilst you could increase the overal speed by turning on concurrency, do you really want to be running hundreds, maybe thousands of api calls using an apply to each, when you can get the job done in two, Select and Filter?

 

DamoBird365_9-1644839535098.png

 

Please let me know if you have been able to implement this within your own solution and the time/efficiency you have introduced as a result.

 

About Me

I am Microsoft 365 Consultant working on the Power Platform, a Microsoft Power Automate Forum Super User and a Microsoft Business Applications MVP (2022).  I have a blog www.DamoBird365.com where I share tips and tricks like this as I explore potential use cases that I am made aware of through work and through play.  I also run a YouTube channel www.youtube.com/c/DamoBird365 where I demonstrate tips like above in my walkthrough demos.  I am happy for folk to contact me via Social Media as DamoBird365 to discuss the technology, learn and share ideas and concepts.

 

%3CLINGO-SUB%20id%3D%22%5C%26quot%3Blingo-sub-3161917%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3EComparing%20two%20arrays%20without%20an%20apply%20to%20each%3F%26lt%3B%5C%2Flingo-sub%26gt%3B%3CLINGO-BODY%20id%3D%22%5C%26quot%3Blingo-body-3161917%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CH2%20id%3D%22%5C%26quot%3Btoc-hId-364120582%5C%26quot%3B%22%20id%3D%22toc-hId-364144638%22%20id%3D%22toc-hId-364144638%22%20id%3D%22toc-hId-364144638%22%3EThe%20two%20arrays%26lt%3B%5C%2FH2%26gt%3B%5Cn%3CP%3EI%20have%20two%20arrays%20in%20Power%20Automate%2C%20whilst%20very%20similar%20in%20structure%20(key%2Fvalue%20pairs)%20the%20unique%20ID%20for%20both%20arrays%20is%20named%20differently%20(id%20vs%20PersonId)%20but%20I%20want%20to%20compare%20both%20and%20return%20only%20those%20that%20do%20not%20appear%20in%20the%20Array%201.%26nbsp%3B%20We%20can%20see%20from%20the%20image%20below%20that%20object%20id%203%20%26amp%3B%204%20are%20not%20present%20in%20Array%202.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347869i4B5030B9E871FEE7%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_0-1644836389622.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_0-1644836389622.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3C%2FH2%3E%3CH2%20id%3D%22%5C%26quot%3Btoc-hId--1443333881%5C%26quot%3B%22%20id%3D%22toc-hId--1443309825%22%20id%3D%22toc-hId--1443309825%22%20id%3D%22toc-hId--1443309825%22%3EUsing%20an%20Apply%20to%20Each%26lt%3B%5C%2FH2%26gt%3B%5Cn%3CP%3EThe%20most%20common%20method%20for%20comparing%20these%20two%20arrays%20will%20involve%20using%20an%20apply%20to%20each%2C%20maybe%20even%20nested%20apply%20to%20each%20actions.%26nbsp%3B%20This%20results%20in%20a%20very%20inefficient%20flow.%26nbsp%3B%20It%20will%20use%20up%20far%20more%20api%20calls%20than%20are%20required%20and%20result%20in%20your%20flow%20taking%20a%20lot%20longer%20to%20run.%26nbsp%3B%20You%20might%20even%20require%20a%20variable%20to%20append%20each%20object%20during%20the%20loop%20and%20a%20final%20compose%20to%20output%20the%20contents%20of%20the%20new%20variable.%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347906iA9D42EC424F9E180%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_1-1644837296978.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_1-1644837296978.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EAbove%20is%20an%20example%20of%20an%20apply%20to%20each%20solution%20that%20when%20run%20on%20the%20two%20original%20arrays%2C%20takes%202%20seconds%20to%20complete%20on%205%20records!%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3C%2FH2%3E%3CH2%20id%3D%22%5C%26quot%3Btoc-hId-1044178952%5C%26quot%3B%22%20id%3D%22toc-hId-1044203008%22%20id%3D%22toc-hId-1044203008%22%20id%3D%22toc-hId-1044203008%22%3EUsing%20Select%20and%20Filter%20Array%20Actions%26lt%3B%5C%2FH2%26gt%3B%5Cn%3C%2FH2%3E%3CH3%20id%3D%22%5C%26quot%3Btoc-hId-1734740426%5C%26quot%3B%22%20id%3D%22toc-hId-1734764482%22%20id%3D%22toc-hId-1734764482%22%20id%3D%22toc-hId-1734764482%22%3E%26nbsp%3B%26lt%3B%5C%2FH3%26gt%3B%5Cn%3C%2FH3%3E%3CH3%20id%3D%22%5C%26quot%3Btoc-hId--72714037%5C%26quot%3B%22%20id%3D%22toc-hId--72689981%22%20id%3D%22toc-hId--72689981%22%20id%3D%22toc-hId--72689981%22%3EUsing%20Select%20to%20establish%20an%20array%20of%20PersonID's%26lt%3B%5C%2FH3%26gt%3B%5Cn%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EFirst%2C%20I%20want%20to%20establish%20an%20array%20of%20PersonID's%2C%20as%20I%20will%20use%20this%20to%20check%20if%20the%20ID%20of%20the%20first%20array%20appears%20in%20the%20Array%20of%20PersonID's.%20This%20can%20be%20done%20using%20a%20select%20action%20in%20text%20mode%2C%20by%20clicking%20on%20the%20icon%20on%20Select%20(bottom%20right%20hand%20corner).%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347910i322F550770FAE16A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_2-1644837637842.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_2-1644837637842.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EThe%20output%20of%20which%20demonstrates%20how%20we%20have%20converted%20our%202nd%20Array%20into%20an%20array%20of%20ID's.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347911i40A6905C11C6A21C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_3-1644837759026.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_3-1644837759026.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3C%2FH3%3E%3CH3%20id%3D%22%5C%26quot%3Btoc-hId--1880168500%5C%26quot%3B%22%20id%3D%22toc-hId--1880144444%22%20id%3D%22toc-hId--1880144444%22%20id%3D%22toc-hId--1880144444%22%3E%26nbsp%3B%26lt%3B%5C%2FH3%26gt%3B%5Cn%3C%2FH3%3E%3CH3%20id%3D%22%5C%26quot%3Btoc-hId-607344333%5C%26quot%3B%22%20id%3D%22toc-hId-607368389%22%20id%3D%22toc-hId-607368389%22%20id%3D%22toc-hId-607368389%22%3EUsing%20Filter%20Array%20to%20establish%20missing%20objects%26lt%3B%5C%2FH3%26gt%3B%5Cn%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EWith%20Array%201%20as%20the%20input%20to%20our%20filter%20array%20action%2C%20we%20can%20check%20if%20the%20id%20%3CSTRONG%3Eitem()%3F%5B'id'%5D%26lt%3B%5C%2FSTRONG%26gt%3B%26nbsp%3Bof%20each%20object%20is%20not%20contained%20(%3CSTRONG%3Edoes%20not%20contain%26lt%3B%5C%2FSTRONG%26gt%3B)%20within%20the%20array%20of%20PersonID's%20we%20have%20created%20using%20the%20select%20previously%20%3CSTRONG%3Ebody('select').%26lt%3B%5C%2FSTRONG%26gt%3B%26nbsp%3B%20This%20is%20all%20achieved%20using%20a%20single%20action%20and%20will%20run%20on%20large%20datasets%20in%20a%20fraction%20of%20a%20second%2C%20using%20only%20the%20single%20api%20call.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSTRONG%3E%3C%2FSTRONG%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347918iFA016E75701F4C10%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_5-1644838204804.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_5-1644838204804.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EBelow%20we%20can%20see%20the%20input%20of%20Array%201%2C%20with%20the%20history%20output%20showing%20only%20id's%203%20%26amp%3B%204%20being%20returned.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347912iD3115700F9CC875B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_4-1644837898424.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_4-1644837898424.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EFinally%2C%20if%20your%20requirement%20is%20to%20get%20an%20array%20of%20id's%20that%20are%20contained%20within%20both%20arrays%2C%20i.e.%20object%20ID's%201%2C%202%20and%205%2C%20you%20can%20simply%20change%20the%20expression%20to%20contains.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347921i703962748A18D7C8%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_7-1644838602675.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_7-1644838602675.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3C%2FH3%3E%3CH2%20id%3D%22%5C%26quot%3Btoc-hId-596841229%5C%26quot%3B%22%20id%3D%22toc-hId-596865285%22%20id%3D%22toc-hId-596865285%22%20id%3D%22toc-hId-596865285%22%3ERunning%20this%20on%20Larger%20Data%20Sets%3F%26lt%3B%5C%2FH2%26gt%3B%5Cn%3CP%3EBelow%20you%20will%20see%20the%20flow%20having%20run%20on%20100%20records%20in%20an%20array.%26nbsp%3B%20The%20Select%2FFilter%20method%20has%20completed%20in%200%20seconds%20once%20more%2C%20but%20the%20apply%20to%20each%20has%20taken%2040%20seconds%20and%20whilst%20you%20could%20increase%20the%20overal%20speed%20by%20turning%20on%20concurrency%2C%20do%20you%20really%20want%20to%20be%20running%20hundreds%2C%20maybe%20thousands%20of%20api%20calls%20using%20an%20apply%20to%20each%2C%20when%20you%20can%20get%20the%20job%20done%20in%20two%2C%20%3CSTRONG%3ESelect%26lt%3B%5C%2FSTRONG%26gt%3B%20and%20%3CSTRONG%3EFilter%26lt%3B%5C%2FSTRONG%26gt%3B%3F%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSTRONG%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22%5C%26quot%3Blia-inline-image-display-wrapper%22%20lia-image-align-inline%3D%22%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fgxcuf89792%2F%5C%26quot%3Bhttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347927i2311D8544ABBA246%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%5C%26quot%3B%22%20role%3D%22%5C%26quot%3Bbutton%5C%26quot%3B%22%20title%3D%22DamoBird365_9-1644839535098.png%22%20alt%3D%22%5C%26quot%3BDamoBird365_9-1644839535098.png%5C%26quot%3B%22%20%2F%3E%26lt%3B%5C%2Fspan%26gt%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3CP%3EPlease%20let%20me%20know%20if%20you%20have%20been%20able%20to%20implement%20this%20within%20your%20own%20solution%20and%20the%20time%2Fefficiency%20you%20have%20introduced%20as%20a%20result.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FP%3E%3C%2FH2%3E%3CH2%20id%3D%22%5C%26quot%3Btoc-hId--1210613234%5C%26quot%3B%22%20id%3D%22toc-hId--1210589178%22%20id%3D%22toc-hId--1210589178%22%20id%3D%22toc-hId--1210589178%22%3E%26nbsp%3B%26lt%3B%5C%2FH2%26gt%3B%5Cn%3C%2FH2%3E%3CH2%20id%3D%22%5C%26quot%3Btoc-hId-1276899599%5C%26quot%3B%22%20id%3D%22toc-hId-1276923655%22%20id%3D%22toc-hId-1276923655%22%20id%3D%22toc-hId-1276923655%22%3EAbout%20Me%26lt%3B%5C%2FH2%26gt%3B%5Cn%3CP%3EI%20am%20Microsoft%20365%20Consultant%20working%20on%20the%20Power%20Platform%2C%20a%20Microsoft%20Power%20Automate%20Forum%20Super%20User%20and%20a%20Microsoft%20Business%20Applications%20MVP%20(2022).%26nbsp%3B%20I%20have%20a%20blog%20%3CA%20href%3D%22%5C%26quot%3Bhttp%3A%2F%2Fwww.DamoBird365.com%5C%26quot%3B%22%20target%3D%22%5C%26quot%3B_blank%5C%26quot%3B%22%20rel%3D%22%5C%26quot%3Bnoopener%20nofollow%20noopener%20noreferrer%22%20nofollow%3D%22%22%20noreferrer%3D%22%22%3Ewww.DamoBird365.com%26lt%3B%5C%2FA%26gt%3B%26nbsp%3Bwhere%20I%20share%20tips%20and%20tricks%20like%20this%20as%20I%20explore%20potential%20use%20cases%20that%20I%20am%20made%20aware%20of%20through%20work%20and%20through%20play.%26nbsp%3B%20I%20also%20run%20a%20YouTube%20channel%20%3C%2FA%3E%3CA%20href%3D%22%5C%26quot%3Bhttp%3A%2F%2Fwww.youtube.com%2Fc%2FDamoBird365%5C%26quot%3B%22%20target%3D%22%5C%26quot%3B_blank%5C%26quot%3B%22%20rel%3D%22%5C%26quot%3Bnoopener%20nofollow%20noopener%20noreferrer%22%20nofollow%3D%22%22%20noreferrer%3D%22%22%3Ewww.youtube.com%2Fc%2FDamoBird365%26lt%3B%5C%2FA%26gt%3B%20where%20I%20demonstrate%20tips%20like%20above%20in%20my%20walkthrough%20demos.%26nbsp%3B%20I%20am%20happy%20for%20folk%20to%20contact%20me%20via%20Social%20Media%20as%20DamoBird365%20to%20discuss%20the%20technology%2C%20learn%20and%20share%20ideas%20and%20concepts.%26lt%3B%5C%2FP%26gt%3B%5Cn%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%26lt%3B%5C%2Flingo-body%26gt%3B%3CLINGO-TEASER%20id%3D%22%5C%26quot%3Blingo-teaser-3161917%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3C%2FLINGO-TEASER%3E%3C%2FP%3E%3CP%3EBring%20efficiency%20to%20your%20cloud%20flows%20with%20select%20and%20filter%20array%20actions.%26nbsp%3B%20Let%20me%20show%20you%20how%20you%20can%20compare%20two%20arrays%20in%20Power%20Automate%20without%20using%20an%20apply%20to%20each.%26lt%3B%5C%2FP%26gt%3B%26lt%3B%5C%2Flingo-teaser%26gt%3B%3C%2FP%3E%3C%2FH2%3E%3C%2FLINGO-BODY%3E%3C%2FLINGO-SUB%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3161917%22%20slang%3D%22en-US%22%3EComparing%20two%20arrays%20without%20an%20apply%20to%20each%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3161917%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId-364120582%22%20id%3D%22toc-hId-1143238931%22%3EThe%20two%20arrays%3C%2FH2%3E%0A%3CP%3EI%20have%20two%20arrays%20in%20Power%20Automate%2C%20whilst%20very%20similar%20in%20structure%20(key%2Fvalue%20pairs)%20the%20unique%20ID%20for%20both%20arrays%20is%20named%20differently%20(id%20vs%20PersonId)%20but%20I%20want%20to%20compare%20both%20and%20return%20only%20those%20that%20do%20not%20appear%20in%20the%20Array%201.%26nbsp%3B%20We%20can%20see%20from%20the%20image%20below%20that%20object%20id%203%20%26amp%3B%204%20are%20not%20present%20in%20Array%202.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_0-1644836389622.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347869i4B5030B9E871FEE7%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_0-1644836389622.png%22%20alt%3D%22DamoBird365_0-1644836389622.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1443333881%22%20id%3D%22toc-hId--664215532%22%3EUsing%20an%20Apply%20to%20Each%3C%2FH2%3E%0A%3CP%3EThe%20most%20common%20method%20for%20comparing%20these%20two%20arrays%20will%20involve%20using%20an%20apply%20to%20each%2C%20maybe%20even%20nested%20apply%20to%20each%20actions.%26nbsp%3B%20This%20results%20in%20a%20very%20inefficient%20flow.%26nbsp%3B%20It%20will%20use%20up%20far%20more%20api%20calls%20than%20are%20required%20and%20result%20in%20your%20flow%20taking%20a%20lot%20longer%20to%20run.%26nbsp%3B%20You%20might%20even%20require%20a%20variable%20to%20append%20each%20object%20during%20the%20loop%20and%20a%20final%20compose%20to%20output%20the%20contents%20of%20the%20new%20variable.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_1-1644837296978.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347906iA9D42EC424F9E180%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_1-1644837296978.png%22%20alt%3D%22DamoBird365_1-1644837296978.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20is%20an%20example%20of%20an%20apply%20to%20each%20solution%20that%20when%20run%20on%20the%20two%20original%20arrays%2C%20takes%202%20seconds%20to%20complete%20on%205%20records!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1044178952%22%20id%3D%22toc-hId-1823297301%22%3EUsing%20Select%20and%20Filter%20Array%20Actions%3C%2FH2%3E%0A%3CH3%20id%3D%22toc-hId-1734740426%22%20id%3D%22toc-hId-144925557%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId--72714037%22%20id%3D%22toc-hId--1662528906%22%3EUsing%20Select%20to%20establish%20an%20array%20of%20PersonID's%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20I%20want%20to%20establish%20an%20array%20of%20PersonID's%2C%20as%20I%20will%20use%20this%20to%20check%20if%20the%20ID%20of%20the%20first%20array%20appears%20in%20the%20Array%20of%20PersonID's.%20This%20can%20be%20done%20using%20a%20select%20action%20in%20text%20mode%2C%20by%20clicking%20on%20the%20icon%20on%20Select%20(bottom%20right%20hand%20corner).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_2-1644837637842.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347910i322F550770FAE16A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_2-1644837637842.png%22%20alt%3D%22DamoBird365_2-1644837637842.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20output%20of%20which%20demonstrates%20how%20we%20have%20converted%20our%202nd%20Array%20into%20an%20array%20of%20ID's.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_3-1644837759026.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347911i40A6905C11C6A21C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_3-1644837759026.png%22%20alt%3D%22DamoBird365_3-1644837759026.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1880168500%22%20id%3D%22toc-hId-824983927%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-607344333%22%20id%3D%22toc-hId--982470536%22%3EUsing%20Filter%20Array%20to%20establish%20missing%20objects%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20Array%201%20as%20the%20input%20to%20our%20filter%20array%20action%2C%20we%20can%20check%20if%20the%20id%20%3CSTRONG%3Eitem()%3F%5B'id'%5D%3C%2FSTRONG%3E%26nbsp%3Bof%20each%20object%20is%20not%20contained%20(%3CSTRONG%3Edoes%20not%20contain%3C%2FSTRONG%3E)%20within%20the%20array%20of%20PersonID's%20we%20have%20created%20using%20the%20select%20previously%20%3CSTRONG%3Ebody('select').%3C%2FSTRONG%3E%26nbsp%3B%20This%20is%20all%20achieved%20using%20a%20single%20action%20and%20will%20run%20on%20large%20datasets%20in%20a%20fraction%20of%20a%20second%2C%20using%20only%20the%20single%20api%20call.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_5-1644838204804.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347918iFA016E75701F4C10%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_5-1644838204804.png%22%20alt%3D%22DamoBird365_5-1644838204804.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBelow%20we%20can%20see%20the%20input%20of%20Array%201%2C%20with%20the%20history%20output%20showing%20only%20id's%203%20%26amp%3B%204%20being%20returned.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_4-1644837898424.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347912iD3115700F9CC875B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_4-1644837898424.png%22%20alt%3D%22DamoBird365_4-1644837898424.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFinally%2C%20if%20your%20requirement%20is%20to%20get%20an%20array%20of%20id's%20that%20are%20contained%20within%20both%20arrays%2C%20i.e.%20object%20ID's%201%2C%202%20and%205%2C%20you%20can%20simply%20change%20the%20expression%20to%20contains.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_7-1644838602675.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347921i703962748A18D7C8%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_7-1644838602675.png%22%20alt%3D%22DamoBird365_7-1644838602675.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-596841229%22%20id%3D%22toc-hId-1375959578%22%3ERunning%20this%20on%20Larger%20Data%20Sets%3F%3C%2FH2%3E%0A%3CP%3EBelow%20you%20will%20see%20the%20flow%20having%20run%20on%20100%20records%20in%20an%20array.%26nbsp%3B%20The%20Select%2FFilter%20method%20has%20completed%20in%200%20seconds%20once%20more%2C%20but%20the%20apply%20to%20each%20has%20taken%2040%20seconds%20and%20whilst%20you%20could%20increase%20the%20overal%20speed%20by%20turning%20on%20concurrency%2C%20do%20you%20really%20want%20to%20be%20running%20hundreds%2C%20maybe%20thousands%20of%20api%20calls%20using%20an%20apply%20to%20each%2C%20when%20you%20can%20get%20the%20job%20done%20in%20two%2C%20%3CSTRONG%3ESelect%3C%2FSTRONG%3E%20and%20%3CSTRONG%3EFilter%3C%2FSTRONG%3E%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_9-1644839535098.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F347927i2311D8544ABBA246%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_9-1644839535098.png%22%20alt%3D%22DamoBird365_9-1644839535098.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20let%20me%20know%20if%20you%20have%20been%20able%20to%20implement%20this%20within%20your%20own%20solution%20and%20the%20time%2Fefficiency%20you%20have%20introduced%20as%20a%20result.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1210613234%22%20id%3D%22toc-hId--431494885%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-1276899599%22%20id%3D%22toc-hId-2056017948%22%3EAbout%20Me%3C%2FH2%3E%0A%3CP%3EI%20am%20Microsoft%20365%20Consultant%20working%20on%20the%20Power%20Platform%2C%20a%20Microsoft%20Power%20Automate%20Forum%20Super%20User%20and%20a%20Microsoft%20Business%20Applications%20MVP%20(2022).%26nbsp%3B%20I%20have%20a%20blog%20%3CA%20href%3D%22http%3A%2F%2Fwww.DamoBird365.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ewww.DamoBird365.com%3C%2FA%3E%26nbsp%3Bwhere%20I%20share%20tips%20and%20tricks%20like%20this%20as%20I%20explore%20potential%20use%20cases%20that%20I%20am%20made%20aware%20of%20through%20work%20and%20through%20play.%26nbsp%3B%20I%20also%20run%20a%20YouTube%20channel%20%3CA%20href%3D%22http%3A%2F%2Fwww.youtube.com%2Fc%2FDamoBird365%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ewww.youtube.com%2Fc%2FDamoBird365%3C%2FA%3E%20where%20I%20demonstrate%20tips%20like%20above%20in%20my%20walkthrough%20demos.%26nbsp%3B%20I%20am%20happy%20for%20folk%20to%20contact%20me%20via%20Social%20Media%20as%20DamoBird365%20to%20discuss%20the%20technology%2C%20learn%20and%20share%20ideas%20and%20concepts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3161917%22%20slang%3D%22en-US%22%3E%3CP%3EBring%20efficiency%20to%20your%20cloud%20flows%20with%20select%20and%20filter%20array%20actions.%26nbsp%3B%20Let%20me%20show%20you%20how%20you%20can%20compare%20two%20arrays%20in%20Power%20Automate%20without%20using%20an%20apply%20to%20each.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Co-Authors
Version history
Last update:
‎Feb 14 2022 03:59 AM
Updated by: