cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FlorC
Frequent Visitor

How to know if an variable is numeric?

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-alzhan-msft
Community Support
Community Support

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.

 

View solution in original post

5 REPLIES 5
ChristianAbata
Super User
Super User

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



Did I answer your question? Please consider to Mark
my post as a solution! to guide others :winking_face:

Proud to be a Flownaut!


If you want you can follow me at www.christianabata.com Quieres contenido en español? Síguenos en Power Automate LA
v-alzhan-msft
Community Support
Community Support

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.

 

View solution in original post

ScottMoore
New Member

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

 

Zed_Yer
Frequent Visitor

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

 

 

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

 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (941)