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

Community site session details

Session Id : ubnLv2H+LHTBLJpl0+H8JK
Power Automate - General Discussion
Answered

Use XPath() to get average

Like (0) ShareShare
ReportReport
Posted on 21 Jul 2022 18:06:14 by 578

Is it possible to use xpath to calculate average? I'm using this expression to sum, and it works perfectly:

xpath(xml(outputs('JSON_Amount')), 'sum(/root/Amount)')

I wonder if there is a way to calculate average. I tried this, but it fails:

xpath(xml(outputs('JSON_Amount')), 'avg(/root/Amount)')

Thanks.

 

 

  • The_Skin Profile Picture
    6 on 11 Apr 2023 at 08:17:41
    Re: Use XPath() to get average

    Yeah, fair call. 😂

     

    Also, don’t worry about the preview status, it’s definitely here to stay.

  • Rhiassuring Profile Picture
    8,688 Moderator on 11 Apr 2023 at 08:07:00
    Re: Use XPath() to get average

    OooOOOo it's in preview! Thanks, @The_Skin ! Creepy name, but, great tip.

  • The_Skin Profile Picture
    6 on 08 Apr 2023 at 06:16:47
    Re: Use XPath() to get average

    Just to chime in on this post, for anyone in future that wants to do aggregation style calculations over data sets, take a look at the Advanced Data Operations connector. There’s an Aggregate function that does it nicely.

     

    https://learn.microsoft.com/en-au/connectors/advanceddataoperatio/#aggregate 

  • PabloD Profile Picture
    62 on 29 Jan 2023 at 14:26:06
    Re: Use XPath() to get average

    You could use sum() and count() in xpath and use that to get the average outside an xpath function.

  • emfuentes27 Profile Picture
    578 on 22 Jul 2022 at 10:23:34
    Re: Use XPath() to get average

    Thanks @Rhiassuring. I did a lot of research also, and I arrived to the same conclusion you did. Your recommendation is exactly what I ended up doing. I just calculated the length and divided by the total, outside the xpath

  • Verified answer
    Rhiassuring Profile Picture
    8,688 Moderator on 22 Jul 2022 at 05:09:50
    Re: Use XPath() to get average

    So unless I'm totally off base - and I did research a bit before typing this - there is still no average function in Power Automate. But what you could do is count the amount of items coming out of the XML and then just divide your sum by that.

    I am hoping someone comes in and says "no, rhia, you are wrong, there is a much better way to do this"....

    R

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Loading complete