Streamlining your Power Automate Flows with the Select Action

In the vast realm of Power Automate, many actions empower users to create efficient and dynamic flows. Among them, the Select action stands out as a versatile tool for array transformation. But what exactly is this action, and how can it be used effectively? In this article, we’ll demystify the Select action, exploring its potential and showcasing practical examples of how it can streamline data handling processes. Whether you’re looking to simplify your array manipulations or optimize your flows, understanding the Select action can be a game changer. Below are simple examples where select actions are extremely valuable:

  • Data Transformation: Use the “Select” action to transform data from one format to another. For instance, you can convert date formats, change text casing, or format numbers according to your requirements.
  • Filtering Data: You can filter data based on specific criteria using the “Select” action. For example, if you have a list of sales transactions, you can filter out transactions above a certain amount or within a specific date range.
  • Data Cleanup: Use the “Select” action to clean up data by removing unnecessary spaces, special characters, or formatting inconsistencies. This is particularly useful when dealing with data imported from different sources.

What is the Select action in Power Automate?

Simply put, the Select action is a way to transform any array into any other array. It is part of the Data Operations set of actions, along with Compose, Filter and Join.

Its configuration on the surface seems straightforward. You pick a “From” array and then enter key/value pairs to build a new array structure. This is where most may become a bit confused. Aren’t arrays just a list of things? Why are we now dealing with what looks like an object? Well there lies the key, arrays are just a list of things, but those things can be objects, for instance, here is a list of food that have properties associated with each:

[
  {
    "name": "Mango",
    "type": "Fruit",
    "color": "Yellow",
    "taste": "Sweet"
  },
  {
    "name": "Lemon",
    "type": "Fruit",
    "color": "Green",
    "taste": "Sour"
  },
  {
    "name": "Chili",
    "type": "Vegetable",
    "color": "Red",
    "taste": "Spicy"
  }
]

This is a valid input for the Select action as it is still an array.

Lets now use the example of removing the “taste” property from each food. We can input the above array into the Select Action, then define the new object structure for each item in the array. We can use the item() expression to access the property values, here is an example:

Note: in the above example, the “Outputs” is just a compose action with the raw json structure pasted into it. In a real world scenario, you’d most likely be working with the output of a query, e.g. a query that gets a list of SharePoint items

You can click on the “Switch Map to text mode” button to get a better view of what’s actually happening here:

This is essentially what a single array item will look like in the final output. So with this example, if we run this flow, we end up with:

[
  {
    "name": "Mango",
    "type": "Fruit",
    "color": "Yellow"
  },
  {
    "name": "Lemon",
    "type": "Fruit",
    "color": "Green"
  },
  {
    "name": "Chili",
    "type": "Vegetable",
    "color": "Red"
  }
]

This may be a simple example, but hopefully you can see how this starts to become very powerful when you realise you can combine this with Power Automates Expression language to really do pretty much any sort of transformation to an input array. You could remove unnecessary properties from response data or apply conditional logic to properties to change their values.

Something that isn’t really conveyed in the documentation, is that you can actually even transform a flat array, e.g. a list of string values, into an array of objects and vice versa (using the text mode in the Map field). Some more advanced cases may be excluding properties based on expression conditions or even filtering entire items out of the array

The added bonus here is that the Select action does in-fact only count as a single action in the Flow, no matter how many items are in your array. So you can achieve the same things you can with an Apply to Each loop, but way faster!

When should I use a Select action over an Apply to Each action?

It can be tricky to know when you can simplify things by using the Select action instead of looping through arrays with an Apply to Each loop, but here are some things to keep in mind when deciding

  • The Select action drastically reduces the amount of time taken to process an array, as it does not require any additional actions or connectors inside it. It also makes your flow more readable and easier to maintain, as you can see the input and output of the Select action at a glance.
  • If you need to run a series of actions for each item in your array, such as sending an email, updating a record, or calling an API, you will need to use an Apply to Each loop. The Select action can only transform the items in the array, but it cannot perform any other operations on them.
  • While you can do complex conditions and filtering inside a Select action, using expressions and functions, it is often necessary to use a Filter action and an Apply to Each loop for more advanced scenarios. For example, if you need to filter an array based on a dynamic value from another action, or if you need to access nested properties of the items in the array, you will need to use a Filter action and an Apply to Each loop.

The Select action can be an incredibly powerful tool and can help to greatly speed up your flows if used correctly. One example is replacing nested Apply to each loops or those within Switch actions, where possible. This can reduce your Flow run times from minutes to seconds.

The Select action is a great way to simplify your flows and make them faster and more readable. However, it is not a replacement for the Apply to Each loop, which is still needed for more complex scenarios. The best practice is to use the Select action whenever you can, but be aware of its limitations and switch to the Apply to Each loop when necessary.