Categories: Microsoft 365

The advanced Pieter’s method in Power Automate

Yesterday, I noticed John Liu and Brian Dang discuss Pieter’s method. This method is referring tot my post of using a compose action inside an apply to each and then referring to this Compose action outside the Apply to each.

If you understand Euler’s Method and L’Hopital’s Rule then I’m sure you can understand Pieter’s method mentioned in Brian’s tweet!

But it is not enough! It is time for the advanced Pieter’s method.

The advanced Pieter’s method

How about other actions inside an Apply to each?

Today I created a flow which gets items from a SharePoint list. The SharePoint list has a multi-people field and I want to just create an array of all the email addresses of all the people that are selected in this People field.

I’m using an Apply to each to run a select and then I’m collecting the output from all of the select outputs in a single Compose action.

As you can see in the above screenshot I’m getting an array of arrays.

Generate the array of arrays

In my Apply to each I’m taking the results from the Get Items action and let the Apply to each action process these items.

Then the select takes the Apply to each items and just selected the People field using the following expression.

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

then the mapping to the Email field is easy by using:

item()['Email']

This will generate the array of arrays. All that is now left is to get the result output the Apply to each using the Compose action with the following expression:

Body('Select')

And when we run the flow we are getting the array of arrays as shown earlier in this post.

Performance

You might have noticed the slow performance of the Apply to each action. 26 seconds is not acceptable!

We need to apply concurrency settings on the apply to each.

After enabling the concurrency setting mentioned in the above post. the apply to each only takes 2 seconds to process 100 items.

In my case the items in the compose were still listed in order of my data feeding the apply to each. I’m however not 100% sure if this is something that we can guarantee or if I was just lucky. In my case I didn’t worry about the order of the data anyway.

What’s next

When looking at performance and you need to build up an array of data you could consider using this method. So far I have looked at the Compose and Select but is there any reason why other actions couldn’t result into the same?

Could we for example use a Get Item action from the SharePoint connector to build up a list of items?

I’m going to put that to the test!

Using my same flow as before I will now include the Get Item action to get each of my 100 items from before.

Then I will collect the body of the Get Item action after the apply to each step.

I got my array of list items back. Ok, I can imagine that this isn’t too exciting as I could just have used the get items action instead of the get item. But now imagine …

You have a list with car brands. Then for each brand of car you have separate lists with models. The get item action inside the apply to each could look at different lists depending on the the car brand processed.

This could create a lot of options. If you have taken advantage of this method then please let me know. I’m interested in hearing your use cases.

Share
Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

View Comments

  • Hi Pieter,

    Thanks for sharing wonderful post , I have question regarding filtering array using another array in fastest way. Could you shed some light on it.

    Thanks

    • Hi Manish,

      Do you mean with filtering an array using another array that you would want to remove items from Array 1 if they exist in Array 2?

      You could use a condition inside your compose using an if function in the compose action.

  • Hi Pieter ,

    Could you share some more details on it. I have used apply to each and filter array inside loop to filter the first array based on second one.

    Thanks

    • Ok, so you have two arrays

      array 1 : [1,3,5,6,7,9]
      array 2 : [1,5,8]

      Now we only want to get the items in arrays 1 that exist in array 2 resulting in [1,5]

      Is that what you are trying to solve?

      You could probably just use the Intersection option for this:
      https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#intersection

      Alternatively if the data is slightly more complicated then you could use the method described in this post and in the compose use the if function like this:

      if(,, null)

      You will now end up with an array of items and blanks, which can be filtered out after you have run the apply to each with a filter action.

  • OK here is what I am trying to achieve :

    Array 1 : [{"id":1,"data":2,"code":3},{"id":2,"data":3,"code":4},{"id":3,"data":4,"code":5}]
    Array 2: [{"data":1,"thread":1},{"data":2,"thread":2},{"data":3,"thread":3},{"data":4,"thread":4}]

    Output : [{"id":1,"data":2,"code":3,"thread":2},{"id":2,"data":3,"code":4,"thread":3},{"id":3,"data":4,"code":5,"thread":4}]

    Thanks

Recent Posts

Calculate the Sum for a SharePoint column in Power Automate

Last week Shane Young asked me about calculating the Sum for a SharePoint column in…

3 hours ago

Object must implement IConvertible in Power Apps

In Power Apps when you do a Patch to create a new item or to…

4 days ago

Get started with adaptive cards in Power Automate

Getting started with adaptive cards can be difficult. In this post i have written some…

1 week ago

Create PDF documents from data in Power Automate

In this post I will look at how to create PDF documents from data. Use…

2 weeks ago

Unnest nested arrays in Power Automate

We all know this problem, you have a nested array in Power Automate but how…

3 weeks ago

Advanced settings not loading in Power Platform

Yesterday one of my clients showed me an issues where the Advanced settings didn't load.…

4 weeks ago
%%footer%%