Skip to main content

Notifications

Community site session details

Community site session details

Session Id : bpozjnbwlW0jS1Q1fHgyMV
Power Automate - Building Flows
Answered

filter array

Like (0) ShareShare
ReportReport
Posted on 1 Oct 2023 21:06:21 by

I am stumped with how to filter my array with another array.  I have two arrays.  One for BuidlingList which has all of our locations and another which is CustodialReportList which has all the survey results for the last month for each buidling.  I need to filter the BuildingList and remove any locations which also appear on the CustodialReportList so that I can then union them to create a final report with all locations, even those who did not receive a custodial report that month.  I've tried a million different configurations, but come up short every time.  Can someone point me to a good tutorial?

 

Grateful for your help.

  • cmegow Profile Picture
    on 08 Oct 2023 at 02:32:44
    Re: filter array

    @creativeopinion thanks.  The video link gave me the information I needed to rework the flow.  Thank you.

  • Verified answer
    creativeopinion Profile Picture
    10,394 Super User 2025 Season 1 on 02 Oct 2023 at 15:17:51
    Re: filter array

    @cmegow Because your Custodial Report List already includes the location—what is reason you need to cross-reference the two lists?.. 

     

    In your case, I don't believe you need to do any filtering. I think the logic in your flow needs to be adjusted. You've indicated that you would like to create a final report that lists all locations—even if they didn't have a Custodial Report. 

     

    In this case, you should do the following. As mentioned in a previous post, you should adjust the way your flow is built. Tip: Limit the top count of items returned to a smaller number while you are building and testing your flow. It will speed up your flow runs—especially if you have a large list of items.

    Apply to Each

    The Apply to each action in your flow (how you've used it isn't necessary). The Get Items action returns the list of items from your SP List in an array. In the screenshot below I've used a Compose action to output the value dynamic content from the Get Items action. 

     

    creativeopinion_5-1696258905370.png

     

    What you've done in your flow is use an Apply to each action to loop through each item returned and appended it to an array. This is unnecessary as the output is the identical to the output that the value dynamic content from the Get Items action.

    creativeopinion_6-1696258905371.png

     

     

    creativeopinion_7-1696258905371.png

     

    Select Action

    Use the Select action to pull the locations only. Note: Scope action is optional—I use them in my flows to keep things organized.

    creativeopinion_12-1696259433641.png

     

     

    This Select action will pull the locations into an array.

     

    Select Custodial Report Data

    For your Custodial Report list, you can use the Select action to pull the values you want to return. This is optional—not required.

    creativeopinion_11-1696259320815.png

    Apply to Each Location

    Now that you have an array of locations, you can use an Apply to Each action to loop through each location. I'm assuming your Building List contains one record per location. 

    creativeopinion_10-1696259213549.png

     

    This next Compose action is optional, however it'll help you to understand what is going on in your flow. Insert a Compose action to hold the current item. This will display the current location being looped through. It can help with troubleshooting.

    creativeopinion_14-1696259500897.png

     

     

    Filter Custodial Report

    I'm unsure if this is a requirement but if you would like to list the report for each school you can then use a Filter Array action to do this. To learn more about how to use the Filter Array action, please refer to this recent YT Tutorial I uploaded.

     

    Insert the Value dynamic content from the Get Items (Custodial Report) action into the From field.

    creativeopinion_0-1696274638384.png

     

    In the first value field, insert the School (or whatever the name of the dynamic content is) dynamic content, leave the operator to is equal to and insert the outputs from the Compose action above (storing the current school being looped through).

    creativeopinion_15-1696259680309.png

     

    Insert a Compose action to store the number of items returned. This is optional but can help with troubleshooting.

    creativeopinion_16-1696259807513.png

     

    Run a test. Verify that the Filter Array action is filtering out your items properly. 

    creativeopinion_1-1696274872197.png

    Initialize a String Variable

    Next you will need to initialize a string variable in the root of your flow. You can add this at the top after the flow trigger or right before the Apply to each action. 

     

    Since you've indicated that you want to display buildings that may not have any custodial reports—you need a container (variable) to store report items if you have any, and another value if you do not.

    creativeopinion_6-1696275389988.png

    Add a Condition Check

    Add a Condition to your flow to check the number of items returned from the Filter Array action. Insert the outputs from the Compose action storing the count of items returned from the Filter Array action into the first value field. 

     

    Change the operator to is not equal to and enter 0. 

     

    In the NO branch (this means the item count is equal to 0—no items returned from the Filter Array action), you can set the variable. I've chosen to use some static text along with dynamic content (the outputs of the Compose action storing the current item — aka the current location being looped through). 

     

    creativeopinion_7-1696275536426.png

     

    Apply to Each (Filter Array Item)

    In the YES branch (meaning the item count is not equal to 0–there are items returned from the Filter Array action), add an Apply to each action. 

     

    Use this action to loop through each item returned from the Filter Array action. 

    creativeopinion_8-1696275905119.png

    Refer to this part of the YT Tutorial that talks about how to access the dynamic content from a Filter Array action. You'll need to use an expression to access the dynamic content from the Filter Array action. 

    creativeopinion_10-1696276211604.png

     

     

    Append to String Variable

    Since the Apply to Each action in the Yes branch will be looping through each filtered custodial item (for the current location), you will need a way to gather the details each time it loops through. 

     

    Add an append to string variable action. This action will collect the content of the Compose action above each time it loops through.

    creativeopinion_11-1696276286445.png

     

    Add a Compose action after the condition branches. If you'd like to add a heading title to the top of the list of custodial reports for the location you can. I'm not sure if you plan on sending a report via email or another way.

     

    I've added an H2 HTML tag to wrap the current location being looped through.

    creativeopinion_15-1696277753203.png

     

    Add a Set Variable action. You will want to clear out the variable each time the Apply to Each action reaches the end of the loop (before it loops through a new location). Otherwise, the append to string action will continue to append to the string which isn't what you want. 

     

    Insert the null function to empty out the variable.

    creativeopinion_13-1696277547447.png

     

    Run a test. Check the outputs of the Compose action with the variable. 

     

    Alternatively, you can use a Create HTML Table action and do without the Apply to Each action if you prefer. 

    creativeopinion_9-1696276141021.png

     

     

    You will need additional actions to pull everything together in a single report.

     

    More to come....

     

    Hope this helps!


    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response!

    👉Watch my tutorials on YouTube
    👉Tips and Tricks on TikTok

     

     

  • cmegow Profile Picture
    on 02 Oct 2023 at 14:40:41
    Re: filter array

    @Nived_Nambiar 

     

    Here is an example of Array 1 BuildingList

     

    "body": [
     {
     "School": "A. Z. Kelley Elementary",
     "Custodial Company": "HES",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     },
     {
     "School": "Academy at Hickory Hollow",
     "Custodial Company": "HES",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     },
     {
     "School": "Dan Mills Elementary",
     "Custodial Company": "ABM",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     },
     {
     "School": "Lawson High",
     "Custodial Company": "ABM",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     }
     ]
    }

     

     

    Here is an example from the CustodialReportList

     

    {
     "body": [
     {
     "School": "Dan Mills Elementary",
     "Custodial Company": "ABM",
     "Entrance": 3,
     "Hallways": 3,
     "Cafeteria": 3,
     "Classrooms": 3,
     "Restrooms": 2,
     "Library": 3,
     "Grounds": 3,
     "Responsiveness": 3,
     "Comments": "<div class=\"ExternalClass49FA630B787649309428A3139E7C504E\">We are in transition with new staff. We need the folowing&#58; \n\nCleaning equipment for the custodian cleaning rooms 19-23. (broom, mop, vacume etc)\n\nWe need a heavy duty vacume for the upstairs.</div>"
     }
     ]
    }

     

    This would be the expected outcome:

     

    "body": [
     {
     "School": "A. Z. Kelley Elementary",
     "Custodial Company": "HES",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     },
     {
     "School": "Academy at Hickory Hollow",
     "Custodial Company": "HES",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     },
     {
     "School": "Lawson High",
     "Custodial Company": "ABM",
     "Entrance": null,
     "Hallways": null,
     "Cafeteria": null,
     "Classrooms": null,
     "Restrooms": null,
     "Library": null,
     "Grounds": null,
     "Comments": null
     }
     ]
    }

     

  • Ramiz Profile Picture
    243 on 02 Oct 2023 at 06:54:26
    Re: filter array

    Hi @cmegow 

    I am doing something similar with dataverse connector using OData filter

    Ramiz_0-1696228625723.png

    Something like this might help you. Filter the buidling list based on location column from custodial report.

    Ramiz_1-1696229594582.png

     

  • Nived_Nambiar Profile Picture
    17,503 Super User 2025 Season 1 on 02 Oct 2023 at 03:40:53
    Re: filter array

    Hi @cmegow 

     

    Could you share input arrays sample and also the output array format which is expected , i have some doubts so may be by looking into this, it will be cleared.

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • cmegow Profile Picture
    on 02 Oct 2023 at 03:20:58
    Re: filter array

    @Ramiz thanks for the tip.  Yes, both arrays have a location field.  I have tried every combination I can think of to make the filter.  Do you have an example that I can see?

  • Ramiz Profile Picture
    243 on 01 Oct 2023 at 21:30:04
    Re: filter array

    Hi @cmegow ,

    Do you have location field in both lists? if yes then you can get all items from custodial report list and then filter the building list using location filter. If the result has some output you can delete or skip that record.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard
Loading started