When you have an array in Power Automate and you would like to add a column, you have 3 ways of doing this.
In some of my posts in the past I already looked at arrays. In this post I will look at the different ways of adding a column to my array. I’ve found a number of ways of doing this and they all have their advantages.
In my examples I’m going to use a compose action to create my initial array. But the arrays can really come from any other data source. This could be a SharePoint list, a SQL database or a table in Dataverse or anything else. Arrays are everywhere.
I’m creating the initial array, with two objects
Then as a run my flow I’m getting an array
Ok, that is good. Now I want to add the length of each title to the array.
The first option is to construct the objects inside an apply to each and then adding the Length property followed by an expression that calculates the length.
length(items('Apply_to_each')?['Title'])
That is easy enough when you only have one property to replicate and it also work probably when you have an array that has predictable propeties, but not every object in each array has to be the same, so this might be some thing that doesn’t always work.
If you have many unpredictable properties in your array you could consider the AddProperty function
Using the following expression you can add a column to whatever object you want. Giving the same result.
addProperty(items('Apply_to_each_2'),'Length', length(items('Apply_to_each_2')?['Title']))
Now you could use a select action and replicate all the properties, but that has got that same problem again of managing optional properties.
Using the addProperty in the select can be really powerful.
With the following expression we’re taking each item in the array and adding our property.
addProperty(item(),'Length', length(item()?['Title']))
Advantages of this last option. Only 1 action used, it is fast and it is easy to understand.
Last week Shane Young asked me about calculating the Sum for a SharePoint column in…
In Power Apps when you do a Patch to create a new item or to…
Getting started with adaptive cards can be difficult. In this post i have written some…
In this post I will look at how to create PDF documents from data. Use…
We all know this problem, you have a nested array in Power Automate but how…
Yesterday one of my clients showed me an issues where the Advanced settings didn't load.…