Calculations in Power Automate and Logic Apps
Cover photos from - https://depositphotos.com/stock-photos/concepts.html Dirt road in the hills near the river

Calculations in Power Automate and Logic Apps

While we have expressions in Logic Apps and Power Automate they are limited in terms of what we can do with them. This blog post aims to give more options to how we deal with numerical values in our automation.

Xpath has been around for a very long time and, if you have worked with SQL Server and T-SQL xpath has been very helpful. You can use the power of xpath in low code automation such as logic apps and power automate as well, so lets get into it.

For this blog we have used Power Automate however the same building blocks can be used in a Logic App both consumption and standard.

No alt text provided for this image

For a data source we use a simple list I have created in SharePoint. This could be any number of sources such as an API call, an excel spreadsheet etc.

No alt text provided for this image

Retrieve your data into the flow, for this example we use a Get items action

No alt text provided for this image

Create an array variable to store the values which we will retrieve.

No alt text provided for this image

Now to iterate through the list and populate the variable with the Coffee count, use an append to array variable action

No alt text provided for this image

Now we get to the part which will make things a wee bit easier, add a compose action and create an XML as per below:

No alt text provided for this image

Test running the flow now will give an output of a simple array with numbers.

No alt text provided for this image

Add another compose action and specify that this is indeed XML

No alt text provided for this image

The data remains the same however it is now highlighted as per XML syntax.

No alt text provided for this image

Now we can use xpath and the available functions (reference document: https://developer.mozilla.org/en-US/docs/Web/XPath/Functions

For our example we will make use of the sum function. Add another Compose action and add the following: xpath(outputs('Compose_2'),'sum(/root/Num)')

No alt text provided for this image

Run your flow/logic app to test

No alt text provided for this image

Voila! The total number of coffees had in a week is 16 which nicely matches our entries in our list. Using xpath opens up an array of calculation methods and is another tool for your toolbox.


Reach out to us on our contact us page if you have any questions or would like to have a chat about how your business can benefit.

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics