Skip to main content

Notifications

Community site session details

Community site session details

Session Id : pQMuUN+t5XN0g79vKCQjiB

One Minute Fixes - Summing up a field

wyattdave Profile Picture wyattdave 406 Super User 2025 Season 1

There is an unlikely expression that can sum up any field/key in an array, and that's the XPATH expression. The XPATH allows you to sum up any level of the array, it does require the json array to be converted to xml, but we have the XML expression for that.

 

The whole process is 3 steps

 

  1. 'Select' to create and array of the numbers,
  2. 'Compose' to create a xml compliant object (root/fieldName).
  3. And finally a 'Compose' / 'Set_variable' to store the sum in by converting it to an xml and using xpath.

 

wyattdave_1-1709244270674.png

 

The final expression converts the object into XML and then uses the XPATH expression.

 

 

 

xpath(xml(outputs('ComposeConvert')), 'sum(/root/number)')

 

 

 

Xpath can do Min,Max,Average,Count as well as Sum. It can also use And/Or operators to filter cross fields, and much more.

 


>----------------------------------------------------------------------------------------------------------------------------------------------
This is a series of short blogs designed to help find solutions for random problems before you ask, keep your eyes out for more

l also do long form and broader Power Platform blogs here https://dev.to/wyattdave

 

 

Comments

*This post is locked for comments

  • trice602 Profile Picture trice602 13,760 Super User 2025 Season 1
    Posted 04 Apr 2024 at 15:13:28
    One Minute Fixes - Summing up a field

    Cool David!  I keep forgetting about xpath!

  • trice480 Profile Picture trice480 1
    Posted 04 Apr 2024 at 15:06:25
    One Minute Fixes - Summing up a field

    Cool! I keep forgetting about xpath!