cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mokono
New Member

Joining 2 arrays based on position and not a common ID

I have exhausted looking for an answer so I am going to ask.

 

I have 2 arrays and I need to join them so that I can then have my table created from a single array and send it out. Here are the arrays:

Array1

Names from a name picker

 

{
  "Resource Name": "First Last"
}

 

2nd Array has a number that is a string input on the front end form but I convert to an array so it looks like this

{
"percent": "100"
}

 

The first array might have 1 or 20 names in it and the 2nd array will have the same number of items as the first array. I need to add the 2nd array to the first as a property so that it comes out like this:

 

[
  {
    "Resource Name": "First Last",
    "Percent Allocated": "100"
  },
  {
    "Resource Name": "First Last",
    "Percent Allocated": "50"
  }
]

 

 

 

How do I merge the arrays based on position of the items, for instance the 2nd array [0] goes to the first array [0] as a property and so on throughout the total number of items?

 

Thank you in advance!

Mokono

1 ACCEPTED SOLUTION

Accepted Solutions
ScottShearer
Super User
Super User

@Mokono 

Here is one solution:

image.pngimage.pngimage.png

The end result looks like this (partial screen shot):

image.png

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

3 REPLIES 3
ScottShearer
Super User
Super User

@Mokono 

Here is one solution:

image.pngimage.pngimage.png

The end result looks like this (partial screen shot):

image.png

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
eliotcole
Super User
Super User

Hi, @Mokono, there's quite a few answers here that might've helped you, but it can be done in a single step with a bit of creative expression writing!

 

Range That Is The Length Of Your Array Then Pick

So ... a quick and easy way to do this is to take the two arrays and then select them into one array, using a range() expression in its From field.

 

In my example, below, you will see that I am referencing my two 'mock' variables, here, but yours will be different references ... just change variables('arrayOneVAR') / variables('arrayTwoVAR') to point to your arrays:

merge-arrays-DELETABLE.jpg
From
range(
	0, 
	length(
		variables('arrayOneVAR')
	)
)
Map
Key Value
Resource Name
variables('arrayOneVAR')[item()]?['Resource Name']
Percentage
variables('arrayTwoVAR')[item()]?['percentage']

What this does is:

  1. Makes a range(), which is an array of numbers from the number before the comma, to the number afterwards.

    Here, that second number is the amount of items in the array containing the Resource Name items.

    This looks like this in my above example:
    [
    	0,
    	1,
    	2
    ]
  2. For each item in that range it then makes the appropriate Key/Value pairs.

    Here you are using the item() (which is simply a number) to select an entry from the previous array.

    So the first entry here is 0 that will select the Resource Name from entry 0 of arrayOneVAR:
    variables('arrayOneVAR')[item(0)]?['Resource Name']

 

Hope this helps!

In the append to array box, what is the expression you are using to pull in each of the different array items as it is cutoff in the screenshot.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,060)