web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / filtering array based ...
Power Automate
Answered

filtering array based on subset of the data

(0) ShareShare
ReportReport
Posted on by

As a baseline.. I have two arrays. Ill need to keep all the data together but I do not care if some of the fields are not an exact match.. Im using the filtered array component to get the delta between the two arrays...comparing from array 1 to array 2 and so it does not contain Item().. Is there a way to only compare a subset of the array... i.e. only look at the companyID part of the array?

 

Example Array 1

[
{
"Name": "John Smith",
"CompanyID": 123,
"Email": "FLNAME@ABC.com"
}
]

 

Example Array 2

[
{
"Name": "Jonathon Smith",
"CompanyID": 123,
"Email": "FLNAME@ABC.com"
}
]

Categories:
I have the same question (0)
  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @jimi_hendrix ,

     

    I made a sample for you.

    vxiaochenmsft_0-1667538906599.png

     

    vxiaochenmsft_1-1667538916666.png

    vxiaochenmsft_2-1667538973918.png

    vxiaochenmsft_3-1667538995319.png

     

    vxiaochenmsft_4-1667539043317.png

     

    Best Regards,

    Wearsky

  • jimi_hendrix Profile Picture
    on at

    Thank you for your reply.. The problem is I need to get away from the apply to each loop as there are 1K records and this takes forever even when concurrency control is on.

     

    Doing the array filter looking at the entire set of objects (but not inside of an apply to each loop), takes 20 SECONDS.. Doing the apply to loop and looking at just one of the parts of the array takes 20 MINUTES    (and its looking at less data, very inefficient).

     

    I was hoping to get a filter array to only look at a select parts of the arrays but return the entire part of the array record when there is a match / not a match.

     

    Thoughts?

     

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    I've spent a bunch of time trying to solve this scenario - it's been fun 🙂

     

    I initially went down the xpath path (pun intended) but ended up with the following which I think should be what you are after (hopefully). Note that I haven't done any testing on large datasets, so not sure about performance.

     

    I have the following arrays of objects:

     

    Array A

    [
     {
     "Name": "John Smith",
     "CompanyID": 123,
     "Email": "John.Smith@ABC.com"
     },
     {
     "Name": "Grant Jenkins",
     "CompanyID": 432,
     "Email": "Grant.Jenkins@ABC.com"
     }
    ]

     

    Array B

    [
     {
     "Name": "Andy Jones",
     "CompanyID": 890,
     "Email": "Andy.Jones@ABC.com"
     },
     {
     "Name": "Johnathan Smith",
     "CompanyID": 123,
     "Email": "John.Smith@ABC.com"
     },
     {
     "Name": "Mary Jones",
     "CompanyID": 300,
     "Email": "Mary.Jones@ABC.com"
     }
    ]

     

    The final output in this case would be:

    [
     {
     "Name": "John Smith",
     "CompanyID": 123,
     "Email": "John.Smith@ABC.com"
     },
     {
     "Name": "Grant Jenkins",
     "CompanyID": 432,
     "Email": "Grant.Jenkins@ABC.com"
     },
     {
     "Name": "Andy Jones",
     "CompanyID": 890,
     "Email": "Andy.Jones@ABC.com"
     },
     {
     "Name": "Mary Jones",
     "CompanyID": 300,
     "Email": "Mary.Jones@ABC.com"
     }
    ]

     

    The full flow is below. I'll go into each of the actions.

    grantjenkins_0-1667718934376.png

     

    Compose A and Compose B contain the arrays of objects.

    grantjenkins_1-1667719022849.png

     

    Select A IDs outputs a simple array of Company IDs from Compose A. The expression used is:

    item()?['CompanyID']

     grantjenkins_2-1667719175771.png

    Example output:

    [
     123,
     432
    ]

     

    Filter array B output will only include items from Compose B where the Company ID is NOT contained in the list of Company IDs (Select A IDs).

    grantjenkins_3-1667719468711.png

     

    The advanced expression is:

    @not(contains(body('Select_A_IDs'), item()?['CompanyID']))

    grantjenkins_5-1667719504255.png

     

    Finally, Compose Combined joins both arrays using the union expression:

    union(outputs('Compose_A'),body('Filter_array_B'))

    grantjenkins_6-1667719585779.png

     

  • jimi_hendrix Profile Picture
    on at

    @grantjenkins , YOU ARE AWESOME!!! Thanks so much for taking the time to run through this.. 

  • jimi_hendrix Profile Picture
    on at

    @grantjenkins , maybe quick question.. is there a way of checking multiple items in the same filter in the advance expression?

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Sorry for the late reply. Yes, you can check across multiple properties. All you would need to do is concatenate the properties you want to check when building up the array and the value you are checking against.

     

    If you take the example flow from before, firstly you would need to change the Select A IDs (which you might want to rename since it wouldn't just be IDs). In this example I'm now checking against both the ID and the Name.

    grantjenkins_0-1668772717446.png

     

    The expression is:

    concat(item()?['CompanyID'], '-', item()?['Name'])

     

    This would give us the following array:

    [
     "123-John Smith",
     "432-Grant Jenkins"
    ]

     

    And secondly, we would need to change the Filter array B so it's also checking both the ID and Name.

    grantjenkins_1-1668772856684.png

     

    The expression is exactly the same as the one for Select A IDs.

    concat(item()?['CompanyID'], '-', item()?['Name'])

     

  • jimi_hendrix Profile Picture
    on at

    No worries.. smart.. I was treating the items separately and didn't think to concat them into a string to compare!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard