cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frog64
Helper II
Helper II

Filter an array in a loop

Hi,

 

I create two arrays in a flow:

  1. ArrayTable with full data for every vendors present in my system: purchase order number, vendor account, item, quantity, email...
  2. UniqueVendor: with the vendor accounts without duplicates

 

I want to create for each vendor present in the UniqueVendor's array, an array with his own records from the ArrayTable, and then send to him an email with his records.

 

I create two nested loops, but my filter is not good, so it fails:

I followed this post but it doesn't work: https://powerusers.microsoft.com/t5/Building-Flows/Iterating-over-distinct-or-grouped-by-column-valu...

 

 

My array UniqueVendor:

40.png

 

The array ArrayTable:

41.png

Here are my loop's issue:

I want to create a loop for each vendor (first loop), and then select all related records before sending an email to the vendor: you can see the results of the test, and then the setup of the flow:

412.png

 

413.png

 

When I send a message on Teams, I can check the data of the condition test: I can see that the second value is not good, because it should have been 00000021 only (not {"Vendor":"00000021"}

414.png

 

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
tom_riha
Super User II
Super User II

Hello @Frog64 ,

instead of a loop inside a loop, try to use the 'Filter array' action:

  • 'Apply to each' of the unique vendors
    • 'Filter array' from the second array, filter only results where Vendor (from the 2nd array) is equal to Vendor (from the 'Apply to each')
    • process the output from the filtered array, it'll contain only the items for given vendor


[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

The 'UniqueVendor' array is also an object, it doesn't contain just the number, but the whole object, e.g.

"Vendor": "00000503"

To get just the vendor number, you can't use the whole 'Current item' dynamic content, you should use only the 'Vendor' value from the object.

items('Apply_to_each')?['Vendor']

If you switch to 'Advanced mode' in the Filter Array, it should look like this:

@equals(item()?['Vendor'], items('Apply_to_each')?['Vendor'])

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

4 REPLIES 4
tom_riha
Super User II
Super User II

Hello @Frog64 ,

instead of a loop inside a loop, try to use the 'Filter array' action:

  • 'Apply to each' of the unique vendors
    • 'Filter array' from the second array, filter only results where Vendor (from the 2nd array) is equal to Vendor (from the 'Apply to each')
    • process the output from the filtered array, it'll contain only the items for given vendor


[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

Hi @tom_riha ,

 

I tried this:

ArrayTable is my table with all the data that I want to filter

416.png

 

But the result is empty: I suppose the fields or syntax are not good in my condition...

 

415.png

 

The 'UniqueVendor' array is also an object, it doesn't contain just the number, but the whole object, e.g.

"Vendor": "00000503"

To get just the vendor number, you can't use the whole 'Current item' dynamic content, you should use only the 'Vendor' value from the object.

items('Apply_to_each')?['Vendor']

If you switch to 'Advanced mode' in the Filter Array, it should look like this:

@equals(item()?['Vendor'], items('Apply_to_each')?['Vendor'])

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

View solution in original post

Frog64
Helper II
Helper II

Thanks for your help!

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (66,539)