Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 7WxGlUu3L2CVmQnNDYsUyy
Power Apps - Building Power Apps
Answered

Power Automate – Output of filter array appears empty but not empty.

Like (0) ShareShare
ReportReport
Posted on 16 Dec 2023 14:15:27 by 9

Output of my array filter:

As reference, the array filter is using a contains function looking for two criteria to match in a large excel file based off the value provided in two variables.  I was testing to see what happens if intentionally setting variable values to something I know is not in the excel table for error handling.  My filter array works perfect for items that are in the excel table but when an item is not in the excel table the output of the filter array is below. 

{

  "name": []

}

 

This to me means that the criteria I was searching for does not exist in the excel table and because of that I want to trigger other actions to take place.  I was trying to use a Compose action and the empty function to then perform certain action if the result was true meaning the array was empty.  However, the empty function returns the results of false and not true so I’m having a little trouble.

 

Can someone please help advise me on what I am not understanding correctly here or make suggestions to achieve the desired results? 

Categories:
  • Pstork1 Profile Picture
    66,135 Most Valuable Professional on 19 Dec 2023 at 22:18:30
    Re: Power Automate – Output of filter array appears empty but not empty.

    You aren't quite understanding the JSON here.  The output of the array is a named property called body which has a value of an array. So when you do length() of the body of the filter array you are doing a length of the body array.  If you store the output of the filter array in a variable or a compose then it will become a JSON string and length on that object won't work.

     

    In your Parse JSON 1 screenshot you have an object called Name that has a property of type array called body. Length in that case should be of the body.  If you look at the filter array you will see that Name isn't there. Its just Body, which is of type array.

  • GoatsRope22 Profile Picture
    9 on 19 Dec 2023 at 22:03:20
    Re: Power Automate – Output of filter array appears empty but not empty.

    @Pstork1, thanks again for all the help here. 🙂 I'm still pretty new to using power automate so I'm still learning the basics.

    Going back to my simple example I realized I was trying to use the length function on the incorrect part of the outputs.

    GoatsRope22_0-1703023262630.png

     

    I guess I'm still just struggling with some of the concepts, but I'll work my way through it.  Thanks again. 

     

    GoatsRope22_1-1703023295495.png

     

  • Verified answer
    Pstork1 Profile Picture
    66,135 Most Valuable Professional on 18 Dec 2023 at 13:13:02
    Re: Power Automate – Output of filter array appears empty but not empty.

    The output of a filter array is an array, not an object. You can see that I am doing just that from my screenshot. Based on the screenshots you are showing I don't see an object either. As you can see from the screenshot below also. The input to a filter array needs to be an array and the output is a filtered version of that array.

     

    Pstork1_0-1702905168493.png

    The square brackets are the JSON syntax for an array, not an object. Objects are curly braces.  An empty array would be []. That suggests there is something wrong with your filter.

     

     

  • GoatsRope22 Profile Picture
    9 on 18 Dec 2023 at 02:56:56
    Re: Power Automate – Output of filter array appears empty but not empty.

    @Pstork1, thank you for the additional detail.  I cannot perform the length function directly on the output of the filter array because it's an object so I get an error.  This is why I had tried using a compose and converting the object to an array so I could use the length function. 

     

    The first image below shows where I have intentionally chosen a value I know won't be found in the excel file the filter array is filtering and shows the output of the filter array.  

     

    The second image shows the error message I get when trying to test the length function directly on the output of the filter array.  "InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'.

    GoatsRope22_0-1702867907410.png

    GoatsRope22_1-1702867943011.png

     

  • Pstork1 Profile Picture
    66,135 Most Valuable Professional on 16 Dec 2023 at 16:40:39
    Re: Power Automate – Output of filter array appears empty but not empty.

    I've tried to replicate your issue, but am unable to.  Here's the flow code that works for me. When I filter out all the records it goes to false. If I don't filter out all the records it goes to true.

    image.png

  • Pstork1 Profile Picture
    66,135 Most Valuable Professional on 16 Dec 2023 at 16:31:58
    Re: Power Automate – Output of filter array appears empty but not empty.

    Are you using length on the output of the filter array directly or are you storing it in something first, like a compose?  I'll try to replicate your issue, but the JSON you are showing for the body is showing an empty array, but which should show a length of 0 not 1.

  • GoatsRope22 Profile Picture
    9 on 16 Dec 2023 at 16:26:48
    Re: Power Automate – Output of filter array appears empty but not empty.

    @Pstork1 , thank you for the response.

     

    I tested for length and the output is 1.  The problem is that even though the output is 1 I'm having trouble with what to do now.  The outputs body of the filter array is [].  

     

    Let me start over.....The output of the filter array for items not containing the criteria is [], see image.  In my example I am looking through a database of zip codes based on a variable defined in the flow and I'm extracting information from another column of data that is associated with the zip code being found in the database.

     

    GoatsRope22_1-1702743077296.png

    If i use the compose action on the outputs of this filter I get this.

    GoatsRope22_2-1702743127823.png

    If I run the Pare JSON action, I also get the same result.  The reason I was using Parse Jason is because if the filter array did find a match then there would be an object with several pieces of information, and I used the Parse Jason to extract only individual values I needed from the output. 

    GoatsRope22_3-1702743219341.png

    When the value is not found in the database I am searching I get the output of [].  Since I believe this is an object I can't directly test the length before converting this to an array.  So I used a compose action and create an array from an object function and this was the output. 

    GoatsRope22_4-1702743639847.png

    Then I can run the a compose action with the length function to get the length

    GoatsRope22_5-1702743677275.png

     

    However, at this point I am stuck because I'm trying to find a way so that when a result isn't returned and I get not information in the body [], I can trigger a message to myself for the value not being found in the database and then go on to other actions. 

     

    I hope this makes sense. 

  • Pstork1 Profile Picture
    66,135 Most Valuable Professional on 16 Dec 2023 at 14:24:52
    Re: Power Automate – Output of filter array appears empty but not empty.

    To test for an empty array use the length() function instead of empty. If the length is zero then the array has no elements. If the length is greater than zero it does. 

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 68 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 41 Super User 2025 Season 1

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 38

Overall leaderboard
Loading started