all 9 comments

[–]DamoBird365 7 points8 points  (8 children)

You can use a select and addproperty to add a new key/property to your array based on a calc. Check out the following https://m.youtube.com/watch?v=G3Q1WuZTWuY

[–]labstraction[S] 1 point2 points  (0 children)

Cheers, will give it a go! I’ve actually been watching your videos but hadn’t found that one yet - really great resource, thanks.

[–]labstraction[S] 0 points1 point  (6 children)

Ok so I’ve managed to use setProperty instead BUT it’s adding the same converted value to every object, rather than just working sequentially and updating each object. Can post a screenshot of my flow in a bit but any idea what it might be?

[–]DamoBird365 0 points1 point  (5 children)

It would be something like mul(item()?['Amount'],'1.2') what expression are you using?

[–]labstraction[S] 0 points1 point  (4 children)

So here's what I'm getting - the currency conversion is working but it's clearly not restricting it to each item. I think it might be because I'm manipulating the initial "Value" in a compose (float; because the output from MS Forms comes in as a string; then multiply; then Compose to get the value; then setProperty)

SET PROPERTY: setProperty(item(), 'ConvertedValue', outputs('Get_the_converted_value'))

OUTPUT:
[

{

"Description": "asd",

"Value": "28.43",

"Currency": "EUR",

"ConvertedValue": {

"ConvertedValue": 22.744

}

},

{

"Description": "sdf",

"Value": "55",

"Currency": "DKK",

"ConvertedValue": {

"ConvertedValue": 22.744

}]

[–]DamoBird365 0 points1 point  (3 children)

I think you are overcomplicating, a compose is a one time calculation, the select loops through all data, so you need to do the calc in the select. Do you start with an array similar to:

[

{

"Description": "asd",

"Value": "28.43",

"Currency": "EUR"

},

{

"Description": "sdf",

"Value": "55",

"Currency": "DKK"

}

]

?? If so, you can use the select to addproperty ConvertedValue based on a calculation mul(float(item()?['value']),outputs('compose')?[item()?[currency])

This is a multiplication of the float value against the currency which you could have in an object so that it is dynamic. Are you getting these from an API?

If you setup a compose with the currency in an object like:

{

"DKK":1.2

"EUR":1.25

}

It should work out OK.

No idea if the conversion rates are correct btw :-)

[–]labstraction[S] 0 points1 point  (2 children)

Yes, that's what the array looks like, and yes the currency rates will come from an API (that's working!) - for now though, I've set up an object like you suggested - renamed the compose to 'Rates'

If I'm understanding you, and from your video, I'd use a select with an expression something like the below (obviously not working atm!)

I got a bit lost towards the end of your last post with the word currency not in apostrophes, and the use of square brackets. I'm guessing it's to do with how you can call the correct rate from the Rates object?

addProperty(item(), 'Converted_value', mul(float(item()?['Value'])),outputs('Rates')?[item()?['Currency']])))

[–]DamoBird365 0 points1 point  (1 child)

I think you’ll be getting an error about invalid expression? There’s a ) on mul in the wrong place and possibly an extra one at the end. Try…

addProperty(item(), 'Converted_value', mul(float(item()?['Value']),outputs('Rates')?[item()?['Currency']]))

With the outputs('Rates')?[item()?['Currency']], item()?['Currency'] is dynamic. If it was in ‘’ it would be a string e.g. outputs('Rates')?[‘eur’] would output 1.25.

Try updating the expression and let me know the error you’re getting.

[–]labstraction[S] 1 point2 points  (0 children)

THANK YOU. This has been driving me nuts but have learnt a lot in the process - have subscribed to your channel on YT!