Categories: Microsoft 365

3 Ways to add a column to an array in Power Automate

When you have an array in Power Automate and you would like to add a column, you have 3 ways of doing this.

Arrays in Power Automate

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.

  • Constructing raw json
  • Using AddProperty
  • Using a select action

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.

Creating the initial array

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.

Add a column to an 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

AddProperty

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']))

The fast road to an additional column

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.

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.

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…

2 days ago

Object must implement IConvertible in Power Apps

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

6 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…

2 weeks 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%%