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 / Filter array based on ...
Power Automate
Answered

Filter array based on nested items - too complicated?

(0) ShareShare
ReportReport
Posted on by 281

Hi there,

I'm trying to filter a JSON array based on items that are nested in the structure. 
Wondering if there is a way that requires less steps than what I've come up with:
image.png


So the "ForEach" steps through every customer in my array and filters the Value-field within the ProductInterests (Choice-field from a SP list). Then a compose checks if the field is empty. If not empty, then append to variable. 
Wondering if it is possible to skip the condition check and use an if-statement instead (but couldn't find a formula that appends to the array-variable).
Also wondering if there is a way to do this without an ForEach-Loop at all, just with code.

This is the JSON:

{
 "body": {
 "value": [
 {
 "ID": 1,
 "Name": "Good Deals",
 "Adress": "Some Street\nSome City",
 "Active": true,
 "ContactPersons": [
 {
 "DisplayName": "Peter",
 "Email": "Peter@GoodDeals.com"
 },
 {
 "DisplayName": "Nina",
 "Email": "Nina@GoodDeals.com"
 }
 ],
 "ProductInterests": [
 {
 "Id": 1,
 "Value": "Bikes"
 },
 {
 "Id": 2,
 "Value": "Boats"
 }
 ],
 "ProductInterests#Id": [1, 2],
 "CompanySize": {
 "Id": 1,
 "Value": "51-100"
 },
 "CompanySize#Id": 1
 },
 {
 "ID": 2,

 "Name": "Fun Factory",
 "Adress": "Some street\nSome city",
 "Active": false,
 "ContactPersons": [
 {
 "DisplayName": "Juan",
 "Email": "Juan@FunFactory.com"
 }
 ],

 "ProductInterests": [
 {
 "Id": 0,
 "Value": "Cars"
 },
 {
 "Id": 1,
 "Value": "Bikes"
 }
 ],

 "ProductInterests#Id": [0, 1],

 "CompanySize": {
 "Id": 0,
 "Value": "1-50"
 },
 "CompanySize#Id": 0
 }
 ]
 }
}

 

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

    Hi @Imke,

     

    You could approach that feature like the below screenshot:

    1. Put the array into the input of Filter array action;

    2. convert the ProductInterests property to a string, then use Contains condition to filter out item contains "Boats":

    @contains(string(item()?['ProductInterests']), 'Boats')

    Screenshot 2021-03-24 135458.jpg

     

    Then the output of filter array will contains items which ProductInterests property contains Boats.

     

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

  • Imke Profile Picture
    281 on at

    Thank you @v-litu-msft ,
    that will do the job most of the times. 
    But it is not limited to the Value-field only and also includes the field names themselves.
    So keeping this thread open a bit just to see if there is a solution that limits the test to the content of the Value field.

  • v-litu-msft Profile Picture
    Microsoft Employee on at

    Hi @Imke,

     

    Ok, you could use the join() function instead of string() function, it will remove the field name:Screenshot 2021-03-24 173959.jpg

     

    Screenshot 2021-03-24 174012.jpg

     

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

  • Imke Profile Picture
    281 on at

    Thank you, but I don't understand how to apply this.

    What is the input (compose) here?
    Are you within a for each-loop?
    How can I select value and then still be able to address item()?['ProductInterests']?
    The value field I'm interested in, is inside the ProductInterests, so no way for me to fetch that before.
     

  • v-litu-msft Profile Picture
    Microsoft Employee on at

    Hi @Imke,

     

    1. The input (compose) here is the original JSON you provided.

    2. It's not within a for each loop, it just did a tiny change based on my previous reply.

    3. You mean like this?

    Screenshot 2021-03-25 162403.jpg

     

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

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!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 557

#2
Valantis Profile Picture

Valantis 328

#3
David_MA Profile Picture

David_MA 264 Super User 2026 Season 1

Last 30 days Overall leaderboard