Math Functions in Power Automate
โ Math Functions in Power Automate
Math functions in Power Automate allow you to perform arithmetic and numeric operations directly inside your flows. From simple calculations like addition and subtraction to more complex rounding, modulus, and absolute value functions, these tools let you process numbers efficiently.
Whether you’re calculating totals, percentages, durations, or dynamic pricing, math functions in Power Automate are essential for building intelligent and data-driven workflows.
๐ Why Use Math Functions in Power Automate?
Youโll need math functions in Power Automate when you:
- Calculate totals or subtotals from numeric fields
- Determine differences between timestamps or values
- Apply tax, discounts, or markups
- Generate dynamic numeric values for conditions
- Control loop indexes or use modulus for logic branching
๐ผ Real-World Use Cases
Use Case | Math Function | Description |
---|---|---|
Calculate invoice total + tax | add() |
Combine subtotal and tax amount |
Discount a product price by 20% | mul() |
Multiply by 0.8 |
Round total to 2 decimal places | round() |
Currency formatting |
Check if a number is even | mod() |
Remainder logic |
Subtract delivery date from today | sub() |
Days remaining |
๐งฎ Math Functions in Power Automate: Function Table
Hereโs a reference table of the most useful math functions in Power Automate:
Function | Purpose | Syntax | Example | Output |
---|---|---|---|---|
add(a, b) |
Adds two numbers | add(10, 5) |
15 |
|
sub(a, b) |
Subtracts b from a | sub(10, 3) |
7 |
|
mul(a, b) |
Multiplies a and b | mul(4, 2) |
8 |
|
div(a, b) |
Divides a by b | div(20, 5) |
4 |
|
mod(a, b) |
Modulo (remainder) | mod(10, 3) |
1 |
|
max(array) |
Returns max number | max(1, 2, 3) |
3 |
|
min(array) |
Returns min number | min(5, 2, 9) |
2 |
|
round(value, digits) |
Rounds to N digits | round(10.456, 2) |
10.46 |
|
abs(value) |
Absolute value | abs(-5) |
5 |
|
ceiling(value) |
Rounds up | ceiling(2.3) |
3 |
|
floor(value) |
Rounds down | floor(2.9) |
2 |
๐งช Examples of Math Functions in Power Automate
1. Calculate Final Price After Discount
mul(triggerBody()?['Price'], 0.9)
Use Case: Apply a 10% discount to a dynamic value.
2. Add Tax to Subtotal
add(triggerBody()?['Subtotal'], triggerBody()?['Tax'])
Use Case: Finalize invoice amounts dynamically.
3. Determine If a Number Is Even
equals(mod(variables('Index'), 2), 0)
Use Case: Create alternating row logic in approval flows or UI outputs.
4. Round Off a Number to 2 Decimals
round(variables('Amount'), 2)
Use Case: Currency formatting for outputs.
5. Calculate Days Remaining
div(sub(ticks(variables('DueDate')), ticks(utcNow())), 864000000000)
Use Case: Determine days left until a due date (1 day = 864000000000 ticks).
โ Best Practices for Using Math Functions in Power Automate
- โ
Use
round()
to ensure clean numeric output in emails or messages - โ
Always validate divisor before using
div()
to avoid division-by-zero errors - โ
Use
variables
to store intermediate results for better readability - โ Combine with conditions or scopes for error-proof calculations
- โ
Use
float()
when dealing with inputs from strings or forms
โ ๏ธ Common Pitfalls with Math Functions
Problem | Cause | Fix |
---|---|---|
Incorrect results | Using string instead of number | Use int() or float() first |
Rounding issues | Missing round() |
Apply it for output formatting |
Flow fails on divide | Division by zero | Check with condition or if() |
Unexpected decimals | Using int() unintentionally |
Use float() or round() |
Invalid expression | Misplaced commas or missing parenthesis | Use Expression Builder to test |
๐ Summary: When to Use Math Functions in Power Automate
Use math functions in Power Automate when you need to:
- Perform any calculation inside your flow
- Add, subtract, multiply, or divide values
- Compare numeric values or determine maximum/minimum
- Round off, format, or present numbers for end users
- Drive numeric logic with modulo, absolute values, or loop indexes