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
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 tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (2,756)