With Power Virtual Agents, you can streamline calculations. The idea of calculator in a chatbot is that the bot will ask the user certain values. A standard formula will be created in Power Automate. It will take the user inputs for the calculation, and return the result back to the user.
The benefits of a calculator chatbot:
- Save time from doing manual calculations. You don’t need to remember the formula and can guarantee accuracy of the results
- Trigger workflows. Based on the result, you can initiate different workflows to occur.
- Data entry: Automatically store the results in a backend source/database. For example, if you need to calculate the floor area of a building, a flow can enter the result into it’s record.
The example shown below uses a flow that can calculate a person’s weight on Mars.
Building the flow
Here is how the flow was created in the example above. Weight on Mars is calculated by the formula:
Weight on Mars = Weight on Earth ÷ 9.81 × 3.711
- Weight on earth is divided by 9.81m/s2, which is earth’s force of gravity. This part of the formula calculates the mass of the person.
- 3.711m/s2 is the gravitational force of Mars. This, multiplied by the person’s mass will give us their weight on Mars.
- The unit of weight does not matter. The user can provide weight in kilograms, pounds, or any other way.
The flow will begin with Power Virtual Agents trigger. The input of Earth weight is a reference to the weight the user has provided throughout the conversation.
Add in a Compose (Data Operation) action for the first part of the calculation. It represents the first part of the formula,
Weight on Earth ÷ 9.81
The expression used is
- div() = Divide values
- triggerBody()[‘number’] = This references the weight on Earth input given by the user
- , 9.81 = the number you want to divide by
The next action will be another Compose (Data Operation) action to represent the last part of weight on Mars formula, Mass × 3.711
The expression used is:
- mul() = multiply values
- outputs(‘Find_mass’) = This references the result of the previous step where mass was calculated. Replace 'Find_mass' with the name of the action as in your flow.
- 3.711 = the number you want to multiply by
The formula part of the flow is now complete. However, it is likely the result will have many decimal places, which does not appear user friendly. You can add a step to round your result. In the example below, the calculated weight on Mars will be rounded to two decimal places. Under the last Compose action, add a new action for Number Functions- Format number. The number being formatted is the output of the previous action.
Finally, to return the value back to Power Virtual Agents, add the result as an output in the Return value(s) back to Power Virtual Agents action.
To test out this bot, build it yourself or download the solution, check it out here on the Bot Sharing Gallery:Calculate your weight on Mars: Space-themed bot!