Power Automate: Check if Text is Numeric

Introduction

We don’t have an IsNumeric Function in Power automate which can at times become a headache as some business decisions will depend on the datatype of data being worked upon. In this article, we will see a dirty workaround to identify if the data at hand is Numeric or Text.

Implementation

We will create a basic power automate that can be triggered manually bypassing the input which will be the Numeric/Text value to check for the datatype. We will also declare a variable that will hold the decision if the data type is number or not. By default, IsNumeric will be set to true which indicates that the number is numeric.

Graphical user interface, text, application, email

Description automatically generated

We will then add a compose action and use the Int function to which we will pass the user input. If the input is a number, the conversion will succeed and the action will not error. However, if the input is a text, the int conversion will fail and the action will error out.

Graphical user interface, application

Description automatically generated

So as to catch the errored-out action, we will add another action set variable where we will set the isNumeric to False.

Graphical user interface, text, application, email

Description automatically generated

we will also set the Configure run after setting for this action to ‘has failed’. Thus, the Set Variable action will be invoked only the input is a text, and due to which the int conversion will fail. Thus, the variable will have the decision isNumeric = false. If the conversion succeeds (as the input is a number), the Set variable action will not run as the previous action has succeeded and the isNumeric will remain to be True

Graphical user interface, application

Description automatically generated

We will also add another action – Condition to check the final status of the variable and add the check isNumeric is equal to true to test the data type based on which corresponding branches will be run with their own logic.

Graphical user interface, application

Description automatically generated

One final step to do is that we need to set the configure run after setting for the condition action to run on both Successful and Skipping of the previous step or else by default only the success run of the previous action will invoke the condition.

Graphical user interface, application

Description automatically generated

Thus the overall flow would look like this:

Graphical user interface, application

Description automatically generated

Test the flow

Let’s manually trigger the flow and pass an Integer value first.

Graphical user interface, application

Description automatically generated

As it is already a number, the 4th step has been skipped and the condition has been evaluated to true indicating the numeric nature of the input

Graphical user interface, application, Teams

Description automatically generated

Now let’s input a text and trigger the flow

Graphical user interface, text, application

Description automatically generated

Thus, the compose action has errored out as the Int function couldn’t convert the text to int and the subsequent step to set the variable isNumeric to false has been run. Even the condition has been evaluated to false indicating the text nature of the input.

Graphical user interface, application, Teams

Description automatically generated

Summary

Thus we saw how we can mimic the IsNumeric function which would help us to check if an input is numerical or textual based on which we can perform some follow-up logic

Related Articles

Author

Author

Priyaranjan KS is a Modern Workplace Architect primarily focused on developing and architecting solutions around Office 365,Power Platform and Azure.He is also a Microsoft Most Valuable Professional(MVP) and a Microsoft Certified Trainer(MCT)

Latest Articles