web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to know if an vari...
Power Automate
Unanswered

How to know if an variable is numeric?

(0) ShareShare
ReportReport
Posted on by 5

Hi everyone!!

Hope can help me, with my problem.

I want to know how I can evaluate an variable to know if is numeric, but I can´t resolve.

 

I read about the function isnumeric but is not avaible on Microsoft Flow :(.

 

And I don´t know how resolve this, somebody can give me another way, how I can do this?

 

Categories:
I have the same question (0)
  • ChristianAbata Profile Picture
    8,951 Most Valuable Professional on at

    hi @FlorC  what you can to enshure a numeric value is use the expresion int() and inside your number. or you can create an array with numbers to see if your output contains numbers inside.

    contains.PNG

  • Verified answer
    v-alzhan-msft Profile Picture
    on at

    Hi @FlorC ,

     

    You could refer to screenshot below to create the flow:

    1.png

     

    You should save the variable in a Compose.

    The expression in the Comoose 2 as below:

     

    int(outputs('Compose'))

     

    The Compose 4 action would run after the Compose 2 has run failed:

    2.png

     

    So if the variable is numeric, the Compose 3 would run, if the variable isn't variable, the Compose 4 would run.

    You could add send email action under the Compose 3 and Compose4 with the result.

     

    Best regards,

    Alice   

    Community Support Team _ Alice Zhang
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

  • Scott Moore Profile Picture
    14 on at

    The xpath shown here will convert your string value to a float

    xpath(xml(json('{value:"99"}')),'number(*/text())')

    The above will return a float for 99

     

    xpath(xml(json('{value:"hello world"}')),'number(*/text())')

    The above will return a float for NaN 

     

    If NaN is returned, a conditional evaluation such as the one shown below, will not error and would return false

    ScottMoore_1-1596657242135.png

     

     

     

    Here it is being used with a variable named office...easier for copy & paste in case I end up back here myself 🙂

    xpath(xml(json(concat('{value:"',variables('office'),'"}'))),'number(*/text())')

     

  • Community Power Platform Member Profile Picture
    on at

    Amazing that there isn't an isNum or isText available, however, the xpath solution here seems like it would do exactly what I want it to do.  Really fancy by the way!  Is there a way to update this to work inside an apply to each loop?  I initialized a variable at the top, and then inside the loop I tried to "Set Variable"  as follows. In fact, I cannot get this to work at all.  Simply trying to do data error correction when a user puts in a text comment when all I want is a number.  I believe the bottom example is the correct syntax, but I put the top one in there to show where I was heading.

     

     

    If(equals(xpath(xml(json('{items('Apply_to_each')?['Num']}')), 'number(*/text())'),0),'TRUE','FALSE') 
    
    xpath(xml(json('{value:"items('Apply_to_each')?['Num']"}')),'number(*/text())')

     

     

  • Nixar Profile Picture
    28 on at

    We can also put Compose action that has int() function inside of Scope like Try block and have the branch where it fails inside another Scope(Catch Block). Doing so I find that the flow doesnot results in Failed.

    Here I have to convert Date from excel to SharePoint Date and so was checking if the date field from excel is numeric or not.

    So, Compose action where I have Convert to Int Function is successful than I will convert that number to Date. If it fails then the flow action will come out of the Scope (Try) and goes to another Scope (Catch). Also Scope (Catch) should be configure to Run after When Scope (Try) fails.

    Nixar_0-1629810276906.png

    Here is overall diagram of the Flow Action

    Nixar_1-1629810336326.png

     

  • DeeTronSEAM Profile Picture
    396 on at

    This is a clever solution @ChristianAbata .  Gave me a quick answer to what I needed.  Thanks!

     

    For others considering all the various answers here, FWIW, if I am understanding correctly what ChristianAbata is describing with his array-contains method, I would point out that:

     

    1) This will only work if the variable being examined is a single character.  If not, you'll want to use substring() to return the character in the string you want to check (assuming the string variable has more than one character).   If you need to check a multi-character variable, probably best to use the more elegant answers from @ScottMoore , @Nixar or @v-alzhan-msft 

     

    2) This array-of-digits method can be reduced to an expression that can be directly used as the condition in an IF action.  You don't have to check the first character, but you have to pick the one character you will examine...and it must exist otherwise substring errors if the string is too short.  E.g.:

     

     

    contains(
     split('0_1_2_3_4_5_6_7_8_9_', '_')
     , substring(
     variables('MyVarToCheckFirstCharacterOfForIsNumeric')
     , 0
     , 1
     )
    )

     

     

     

  • DeadFishEddie Profile Picture
    23 on at

    Drawing on the other solutions here, this is a solution that worked for my instance.

     

    DeadFishEddie_0-1643056039296.png

     

    • Initialize an integer variable
    • set variable 2 uses the string input from the user to set the integer variable value
      • int(variables('strInput'))
      • this should succeed if it is numeric and fail if not
    • Set Variable 3 is flagged to run if Set Variable 2 fails and sets the value of my variable to -1
    • "Condition 3" is the next step in my flow and is flagged to run if Set Variable 3 is successful or is skipped.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 523 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard