cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Heartholme
Continued Contributor
Continued Contributor

Dynamic appending of values containing specific strings

Hello, 

 

I have an issue which I have trouble getting past. 

 

I have filtered out a 'shipment' from an array with multiple shipments and I have the following array which is with my values I want to use further: 

 

[
{
"ShipmentNumber": "1005",
"Analysis1": 23,
"Analysis2": 135655,
"Analysis3": null,
"Analysis4": 0,
"Analysis5": "10",
"Analysis6": "7",
"FlourPERC": 0.1,
"FlourProducedFrom": "zone 2, zone 4, zone 5",
"MilkPerc": 0.2,
"MilkProducedFrom": "zone 44,zone 45, zone 46, zone 47",
"YeastPerc": 0.2,
"YeastProducedFrom": "Zone 1, Zone 2, Zone 4",
"WheatPERC": 95.5,
"WheatProducedFrom": "Zone 10 , Zone 12",
}
]

 

What I would like is to append the following information into an array variable with the following three variables listed down below.  Since these values are not constant, and there is a different composition for each product, which I would to avoid making different flows for each composition. 

 

1. Product names, I.e "WheatPerc" without Perc. 

 

2. The percentage of product in the end product. The value from FlourPerc, WheatPerc etc, ie value from all variables containing 'Perc'. 

 

3. The values from all variables containing 'ProducedFrom'.

 

The rest of the values above "FlourPerc" are constant and not relevant, like shipmentnumber, analysis data etc. 

 

I'm quite stuck, and can't seem to see how I can append the values I want in a good way. I've looked at something like this: 

Heartholme_0-1641482294824.png

But it's appending the values containing the differnt values that are an issue. 

 

Any help would be highly apriciated! 

 

Edit: Typo. 

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Super User
Super User

Hi @Heartholme 

 

Can you explain with a before and an after array?  

 

Are you looking for

 

{

"Product Name":"Flour",

"Percentage":"0.1",

"ProducedFrom":"zone 2, zone 4, zone 5"

}


DamoBird365_0-1641488978156.png

 

Here is how it is done.

 

Using a compose to hold your initial object, I have then created an array of products in another compose, including a random one - cabbage.

 

DamoBird365_1-1641488996572.png

Then using select and the array of products as input/from, I can construct my new key/value pairs

 

Product Name is item()

Percentage is outputs('Object')?[concat(item(),'Perc')]

ProducedFrom is outputs('Object')?[concat(item(),'ProducedFrom')]

 

I use item from the array of products to create dynamic expressions.

 

The final array will include all products, even if not in the original object but you could filter these out using filter array action if need be as the values for percentage and producedfrom will be NULL.

 

Hope I've got you right - otherwise - hope you learned something 🙂

 

Please consider accepting my answer as a solution if it helps to solve your problem.

Cheers
Damien

Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

 

View solution in original post

2 REPLIES 2
DamoBird365
Super User
Super User

Hi @Heartholme 

 

Can you explain with a before and an after array?  

 

Are you looking for

 

{

"Product Name":"Flour",

"Percentage":"0.1",

"ProducedFrom":"zone 2, zone 4, zone 5"

}


DamoBird365_0-1641488978156.png

 

Here is how it is done.

 

Using a compose to hold your initial object, I have then created an array of products in another compose, including a random one - cabbage.

 

DamoBird365_1-1641488996572.png

Then using select and the array of products as input/from, I can construct my new key/value pairs

 

Product Name is item()

Percentage is outputs('Object')?[concat(item(),'Perc')]

ProducedFrom is outputs('Object')?[concat(item(),'ProducedFrom')]

 

I use item from the array of products to create dynamic expressions.

 

The final array will include all products, even if not in the original object but you could filter these out using filter array action if need be as the values for percentage and producedfrom will be NULL.

 

Hope I've got you right - otherwise - hope you learned something 🙂

 

Please consider accepting my answer as a solution if it helps to solve your problem.

Cheers
Damien

Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

 

Heartholme
Continued Contributor
Continued Contributor

This is amazing. Thanks a lot for you help!

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.

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.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Users online (2,538)