In this post I’m going through one of the ways to increase the performance of your flows.
In this post I will use the example of counting the number of documents in a SharePoint library.
The bad way
First of all I will start with the Get files action ( you could of course use the REST API and use the Send HTTP Request to SharePoint).
We will now find a number of documents back and we want to count these. So something like this:
That is going to be, ok if you can guarantee only a few documents in a library but as time goes on your flow will not perform for very long as more and more documents are uploaded.
You might have noticed the length function in the Expressions tab so initilizing a varbale with length(body(‘Get_Files’)) could work, but this doesn’t work as the Get files is returning JSON.
All we need to do is create an array!
The Speedy Way
The Select function is used for the creation of the array
where you can see item() simply use item()?[‘ID’] to select the ID for each item in the JSON returned by the Get files action.
Then a length(body(‘Select’)) will give you the number of items in your library:
Now just run your flow and the number of documents is returned:
Performance-wise this makes a big difference. In our first example
There we ran the following actions
- 1 trigger.
- 1 Get files
- 1 Apply to each
- 8 Increment variable
So that is 11 steps in total.
With the optimized example we only had:
- 1 trigger
- 1 get files
- 1 select
- 1 Initialize variable (and this isn’t really needed, as you could use the expression within the following steps of your overall flow)
11 thoughts on “Microsoft Flow – How to make your flows perform better”
Is there a way to make the Select Expression create a nested array? I have a list with a supervisorName column and employeeName column. Each supervisor has many employees. I was hoping Select would provide a way for me to create an array of each supervisor and their respective employees.
I had something similar recently. I went for a csv alike approach using the join function.this way I would set people to something like user1;user2;user3 then as I needed to get to the data I would split the text using the split function.
I have a list of items in sharepoint, and one of the columns is an Assigned To. It can contain multiple people. I am trying to send a daily summary email of the open items, and who they are assigned to. For each row, I just want a concatenated list of the display names without all of the extra user info. I know how to do it with nested Apply to each, but this is extremely inefficient, since it’s a very large list. Is it possible to do this within the select statement?
It envision it would be something like join(items()?[‘AssignedTo’]?[‘DisplayName’], ‘, ‘), but that’s not working.
I just want it to look like: Bob Smith, Joe Schmo, Jane Williams
That is a tricky one. I don’t think that you can avoid the double Apply to each step here. However you might be able to avoid the nested Apply to each.
I would consider first to convert the assigned to into a the comma separated text. Maybe store this in a separate field.
Then once you have that data run an apply to each in the list items like you were planning to.
Now you will have choice to make. Do you do the conversion as part of your flow or maybe as a separate flow that sets an additional field only when an item is being modified. Personally I would consider creating a second flow that does the ‘clean up’.
Thanks for the reply Pieter, You confirmed what I was thinking unfortunately. It’s too bad because the filter is so much more efficient.
I will probably do the conversion as a separate one-time flow, since we have several thousand records, and modify all the add & update flows, to ensure the field stays up to date going forward.
Another thought is, can I just somehow include the AssignedTo object in the table/email, and let outlook resolve it? I don’t care if the report shows their profile picture or initials. I just want it to show them somehow.
I managed to join the assignto people field with the following expression in a select mapping:
However this does mean that you get a single text value with all the details. Unfortunately you will get a lot of junk here and might have to clean that up at the later stage. I used *** as a separator but you can of course use anything.
That doesn’t seem to work for me. I’d love to see some screen shot examples of what you are doing and how it fits in.
Does this help:
Yes, It looks like you’re just getting 1 item back from your Get Items which may be the difference, that or the from statement in the Select
The get items is returning an array
The select is fed by the following:
Even when I get the get items to return multiple items it still works.
OK, I had to change the From Statement, and that made the join work. Now to figure how to efficiently parse that down the line. Is there a way I can send a screen show of what I’m seeing?