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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Build an xpath express...
Power Automate
Unanswered

Build an xpath expression with sum()

(0) ShareShare
ReportReport
Posted on by 12

Hi there,

I am trying to build a flow with XPath in the 'Select'. When I try to add the sum() to the XPath below, I get 'an invalid expression' error.

 

This statement works!

xpath(outputs('Compose_XML'), concat('(//values[EmployeeNumber=',item(),']/Email)[1]/text()')))

 

This statement with the sum() doesn't work!

xpath(outputs('Compose_XML'), concat('(sum//values[EmployeeNumber=',item(),']/Email)[1]/text()')))

 

I appreciate any help!

 

Thanks in advance!

Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,855 Most Valuable Professional on at

    Hi @chandlers201,

     

    Afaik the sum function needs to have parentheses as well, which are missing in your example:

    https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms256160(v=vs.100)

     

    Below is an example (based on Example 7 of the Microsoft docs, https://learn.microsoft.com/en-gb/azure/logic-apps/workflow-definition-language-functions-reference#xpath)

     

    xpath(xml(outputs('Compose_XML')), 'sum(/produce/item/count)')

     

    sumfunction_example.png

     

  • chandlers201 Profile Picture
    12 on at

    Thanks for your response. I am using the 'Select' to access the list of accounts, (e.g. ACT001, ACT002, etc). In the XPath expression, I have used concat around the item() to return me each account. I am not sure how to build the XPath with the sum()? Do I need to use concat?

    chandlers201_0-1715259834769.png

     

  • Expiscornovus Profile Picture
    33,855 Most Valuable Professional on at

    Hi @chandlers201,

     

    Can you share the xml which is used in the Compose XML? Interested to see the schema of your xml. Obfuscate data if needed.

     

    And what are you trying to sum?

  • chandlers201 Profile Picture
    12 on at

    Hi there

    chandlers201_0-1715270217062.png

    using the sum() to add up the amount.

     

     

  • Expiscornovus Profile Picture
    33,855 Most Valuable Professional on at

    Hi @chandlers201,

     

    Thanks for sharing.

     

    Just to double check. Do you need the total amount of all accounts together? Or the total amount per unique account?

     

    In case of the first scenario you could just use the below in a Compose action.

     

    xpath(xml(outputs('Compose_XML')), 'sum(/root/values/amount)')

     

    sumamount_total.png

     

    Test run

     

    totaltest.png

  • chandlers201 Profile Picture
    12 on at

    Thanks for that. I am looking for the total amount per unique account.

     

     

  • Expiscornovus Profile Picture
    33,855 Most Valuable Professional on at

    Hi @chandlers201,

     

    Can you try the below?

     

    From

    xpath(xml(outputs('Compose_XML')), '//root/values')

     

    Account

    join(xpath(item(), '//accountid[1]/text()'), '')

     

    Amount

    xpath(xml(outputs('Compose_XML')), concat('sum(//root/values[accountid=', '''', join(xpath(item(), '//accountid[1]/text()'), ''), '''', ']/amount)'))

     

    sumbydistinctaccount.png

     

    My test run

     

    sumamount_test.png

     

    You will also need to use a union after the select to remove the duplicates.

    union(body('Select'),body('Select'))

     

  • chandlers201 Profile Picture
    12 on at

    Thanks for this. I really appreciate it.

    join(xpath(item(), '//accountid[1]/text()'), '')

    I tried running this statement but I am getting an error. Does it need to be converted to XML?

     

    Screenshot 2024-05-11 at 18.15.29.png
    Screenshot 2024-05-11 at 18.24.36.png
  • chandlers201 Profile Picture
    12 on at

    Screenshot 2024-05-11 at 18.27.25.png

    xpath(xml(outputs('Compose_XML')),'sum(//values/finops_amount)')

    Screenshot 2024-05-11 at 18.30.17.png

  • Expiscornovus Profile Picture
    33,855 Most Valuable Professional on at

    Hi @chandlers201,

     

    Yes, I converted what is in the Compose (which will be text as output) to xml first, before using it in the Select action From field.

     

    I see you have a different xml schema now compared to what you shared earlier.

     

    Try and update the xpath expressions to use the names of your xml schema, below is an updated example.

     

    From field of the Select action

    xpath(xml(outputs('Compose_XML')), '//root/values')

     

    Account value in the Map field of the Select action

    join(xpath(item(), '//finops_accountid[1]/text()'), '')

     

    Amount value in the Map field of the Select action

    xpath(xml(outputs('Compose_XML')), concat('sum(//root/values[finops_accountid=', '''', join(xpath(item(), '//finops_accountid[1]/text()'), ''), '''', ']/finops_amount)'))

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 464

#2
Haque Profile Picture

Haque 431

#3
David_MA Profile Picture

David_MA 323 Super User 2026 Season 1

Last 30 days Overall leaderboard