Mastering the INT Function in Power Automate
Understanding the INT Function in Power Automate
Power Automate is equipped with a rich library of built-in expression functions designed to transform and manipulate data effectively. Among these, the INT function stands out as a frequently used tool when dealing with numeric values. Its primary role is to convert a number into an integer by truncating the decimal portion, thereby returning only the whole number.
What is the INT Function?
The INT function returns the integer portion of a given number. It essentially strips away any digits after the decimal point.
Syntax
The syntax for the INT function is straightforward:
int(value)
Examples
int(25.99)results in25int(10.75)results in10int(100.01)results in100
Why Use the INT Function?
The INT function proves invaluable in several scenarios:
- Removing Decimal Places: When you need to present or use numbers without their fractional parts.
- Preparing Data for Calculations: Ensuring that calculations are performed using whole numbers, which can sometimes simplify logic or meet specific business rules.
- Converting User Input: Standardizing numerical input received from users, which might otherwise contain decimals.
- Working with SharePoint Numbers: Power Automate often interacts with SharePoint lists, and the
INTfunction can help process numeric columns. - Processing Financial or Quantity Values: For applications where only whole units or amounts are relevant.
- Performing Comparisons: Simplifying comparisons by working with integer values.
Example 1: Convert Decimal Number
If you have an input number like 25.89 and apply the expression int(25.89), the output will be 25.
Example 2: Convert Dynamic Content
When dealing with dynamic content, such as an 'Amount' field from a trigger, you can use:
int(triggerBody()?['Amount'])
If the 'Amount' contains 150.95, the output will be 150.
Example 3: Calculate Working Hours
Imagine a flow that calculates total hours, resulting in a value like 7.85. By applying the INT function to a variable holding this value:
int(variables('TotalHours'))
The output will be 7. This is particularly useful for reporting whole hours worked.
Example 4: SharePoint Number Processing
When retrieving numeric data from SharePoint columns, like a 'Quantity' column:
int(items('Apply_to_each')?['Quantity'])
This allows you to store or use only integer values for inventory calculations, ensuring accuracy in tracking item counts.
Difference Between INT and ROUND
It's crucial to distinguish the INT function from the ROUND function:
- INT: Simply removes the decimal part. For example,
int(5.99)results in5. - ROUND: Performs mathematical rounding to a specified number of decimal places. For example,
round(5.99, 0)results in6.
The key difference is that INT truncates (cuts off) decimals, while ROUND rounds to the nearest whole number.
Common Use Cases
The INT function finds practical application in various business processes:
- Invoice Processing: Converting quantities to whole numbers for accurate billing.
- Inventory Management: Tracking item counts as whole units.
- Employee Timesheets: Calculating whole working hours for payroll or reporting.
- Reporting: Displaying cleaner, more readable numeric values by removing insignificant decimal places.
- Financial Automation: Performing calculations that require integer-based values, especially for currency or units.
Best Practices
To effectively utilize the INT function, consider these best practices:
- Validate Input: Always validate input values before conversion to ensure they are indeed numbers.
- Handle Nulls: Use functions like
coalesce()to handle potential null values gracefully. - Appropriate Use: Employ
INTonly when decimal precision is not required for the specific calculation or data representation. - Combine with Actions: Integrate
INTwithComposeandVariableactions for clarity and reusability within your flows. - Test Negative Numbers: Be mindful of how
INTbehaves with negative numbers; it still truncates towards zero (e.g.,int(-5.99)is-5).
Benefits of Using INT
Leveraging the INT function offers several advantages:
- Cleaner Data: Eliminates unnecessary decimal digits, presenting data in a more digestible format.
- Better Calculations: Ensures consistency by working with integer values, reducing potential errors in calculations.
- Simplified Reporting: Makes reports easier to read and understand for stakeholders who prefer whole numbers.
- Improved Automation: Contributes to simpler and more robust automation workflows by standardizing numeric data.
Conclusion
The INT function is a simple yet powerful expression in Power Automate that effectively converts decimal values into integers. Whether you are working with data from SharePoint, Dataverse, Excel, or external APIs, the INT function provides a reliable method to simplify numeric data, enhance calculation accuracy, and streamline your automated workflows.