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.
Yeah, fair call. 😂
Also, don’t worry about the preview status, it’s definitely here to stay.
OooOOOo it's in preview! Thanks, @The_Skin ! Creepy name, but, great tip.
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
You could use sum() and count() in xpath and use that to get the average outside an xpath function.
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
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
Michael E. Gernaey
497
Super User 2025 Season 2
David_MA
436
Super User 2025 Season 2
Riyaz_riz11
244
Super User 2025 Season 2