Skip to main content

Notifications

Community site session details

Community site session details

Session Id : Jhuw6e7NHg885SohOZJD/f
Power Automate - Building Flows
Answered

How to know if an variable is numeric?

Like (0) ShareShare
ReportReport
Posted on 19 May 2020 21:34:49 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?

 

  • DeadFishEddie Profile Picture
    23 on 24 Jan 2022 at 20:34:18
    Re: How to know if an variable is numeric?

    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.
  • DeeTronSEAM Profile Picture
    396 on 04 Dec 2021 at 18:00:21
    Re: How to know if an variable is numeric?

    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
     )
    )

     

     

     

  • Nixar Profile Picture
    28 on 24 Aug 2021 at 13:05:47
    Re: How to know if an variable is numeric?

    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

     

  • Community Power Platform Member Profile Picture
    on 22 Mar 2021 at 18:01:51
    Re: How to know if an variable is numeric?

    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())')

     

     

  • Scott Moore Profile Picture
    12 on 05 Aug 2020 at 19:54:58
    Re: How to know if an variable is numeric?

    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())')

     

  • Verified answer
    v-alzhan-msft Profile Picture
    on 20 May 2020 at 08:09:49
    Re: How to know if an variable is numeric?

    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.

     

  • ChristianAbata Profile Picture
    8,947 Most Valuable Professional on 19 May 2020 at 22:31:02
    Re: How to know if an variable is numeric?

    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

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,745 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard
Loading started