cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hraz
Regular Visitor

Filter numbers

I have an string and I split it by some separator. The some of the items are strings and some of them are numbers as string. For example:

 

foo_1_bar123_230

I want to continue with the numbers only: "1" and "230".

 

Unfortunately, "int(CurrentItem)" throws an error for the items that are not a real numbers (for example "foo" is failing").

 

How can I filter only the numbers "1" and "230"?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: Filter numbers

Hi @hraz 

 

right before update a work item in your for loop

do a compose statement and type the following expression

int(item())   

 

Then after the expression do a parallel branch

Branch logic 1 - update work item   (configure run after with compose successful)

Branch logic 2 - write another compose statement with some dummy text  (configure run after with compose failed)

 

 

 

 

 

View solution in original post

13 REPLIES 13
Super User
Super User

Re: Filter numbers

@hraz 

Hi there!  Are the numbers always in the same position?  Meaning:  If the underscore is your delimiter, will the integers always be in positions 2 and 4?

 

-Ed-

 

hraz
Regular Visitor

Re: Filter numbers

@edgonzales thanks for the fast reply.

 

No, the numbers are not in the same position and actually the number of the numbers can be changed.

 

For example:

foo_123
123_bar
foo_123_bar_12
foo_1_4

Are legit..

 

As I see it there are two options, or check somehow that the numbers are really numbers before the action, or ignore the error that the action throws (because if it run on a string, it fails and then the status of the entire flow considered as failed

Highlighted
Dual Super User
Dual Super User

Re: Filter numbers

Hi @hraz 

 

It will error out 

Your best bet will be do error handling using configure run after

so even if step fails your flow continues to execute

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Super User
Super User

Re: Filter numbers

Ya, I think you're on the right track since it moves around.  Do a split on the delimiter, then set everything to an INT and cast aside anything that errors out.

I don't know if Flow has an equiv to IFERROR(), but I have seen people talk about error handling, so something is in there.

 

Keep us posted.

 

-Ed-

 

Dual Super User
Dual Super User

Re: Filter numbers

Hi @hraz 

 

Just tested it and it works

append to array if int(item()) succeeds

and continue looping if it fails

Not the most elegant solution but it works

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

hraz
Regular Visitor

Re: Filter numbers

my flow do the split in "Apply to each" and the relevant action is right after. The problem is that run after in this case is blocked:

Cannot configure run after on the first action in a scope.

Because this is in "Apply to each" I also can't set a variable there...

Dual Super User
Dual Super User

Re: Filter numbers

Hi @hraz 

 

do parallel branch where in you convert to int

 

successful side - add to array of numbers

unseuccessful - just add a basic action - compose

 

share screenshot of ur Flow if having issues

hraz
Regular Visitor

Re: Filter numbers

Actually is the first time I'm using Microsoft Flow. Here is part of my flow:
Annotation 2019-08-07 213418.png

 

Can you please explain it again? How can I do a parallel branch for successful / unsuccessful side?

Dual Super User
Dual Super User

Re: Filter numbers

Hi @hraz 

 

right before update a work item in your for loop

do a compose statement and type the following expression

int(item())   

 

Then after the expression do a parallel branch

Branch logic 1 - update work item   (configure run after with compose successful)

Branch logic 2 - write another compose statement with some dummy text  (configure run after with compose failed)

 

 

 

 

 

View solution in original post

hraz
Regular Visitor

Re: Filter numbers

Got it. Thanks! I will try it out!

hraz
Regular Visitor

Re: Filter numbers

I've just saw that it continue to be marked as failed even if it run after a failiure. But I don't want it to be marked as failed if it failed by string that is not a number...

 

Annotation 2019-08-08 105630.png

Super User
Super User

Re: Filter numbers

Hi @hraz ,

 

Yes it will give you an exception and set the flow action as failed.

 

If you looking to check whether a text is numeric there is no out of the box flow function available now but you can check each character is a digit falling between ( 0 to 9) or not. Here you need to utilise substring function and a loop to extract each characters from the text. I have answered a solution for this. Here is the link below. Please ignore the title which say count number of digits. It's a little bit misleading.

 

https://powerusers.microsoft.com/t5/Building-Flows/Count-number-of-digits-in-email-subject/m-p/33303...

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
hraz
Regular Visitor

Re: Filter numbers

Thanks I will give it a try :). We really have to add this function built it

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (6,994)