web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Adding a calculated co...
Power Automate
Answered

Adding a calculated column to array

(1) ShareShare
ReportReport
Posted on by 5
Hi,
I have this array that has two columns, "Price" and "Quantity"
<root>
  <array>
    <Product>A
    </Product>
    <Price>120
    </Price>
    <Quantity>45307
    </Quantity>
  </array>
  <array>
    <Product>B
    </Product>
    <Price>58
    </Price>
    <Quantity>2530
    </Quantity>
  </array>
  <array>
    <Product>C
    </Product>
    <Price>165
    </Price>
    <Quantity>685
    </Quantity>
  </array>
</root>
 
I would like to add a calculated column to this array to calculate the total value for each product, "Value" = Price * Quantity. I am looking for a XPath solution rather than "Apply to each", if possible.
 
Thanks.
Categories:
I have the same question (0)
  • Verified answer
    Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at
     
    Try like as shown below
     
    1. Use a compose action to store the xml input
     
    2. Use Select action to perform the calculated column operation as shown below
    Expression: 
    json(xml(outputs('Compose')))?['root/array']
     
     
    Expression: 
    addProperty(item(),'Value',string(mul(float(item()?['Price']),float(item()?['Quantity']))))
     
     
    3. Use a compose action to structure the array like below
     
    4. use compose action to convert the json in above compose action to xml.
     
     
    Final XML looks like this
    <root><array><Product>A</Product><Price>120</Price><Quantity>45307</Quantity><Value>5436840</Value></array><array><Product>B</Product><Price>58 </Price><Quantity>2530</Quantity><Value>146740</Value></array><array><Product>C</Product><Price>165</Price><Quantity>685 </Quantity><Value>113025</Value></array></root>

    Thanks & Regards,
    Nived N

    Stay connected:
    LinkedIn | YouTube | Blogs

    Was this answer helpful?
    If yes, please mark it as the solution by selecting the checkbox in the discussion thread.
    Your feedback motivates me to keep contributing. Thank you!

  • CU20021609-0 Profile Picture
    5 on at
    Thanks @Nived_Nambiar. This is exactly what I was looking for,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard