cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hraz
Level: Powered On

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
RezaDorrani
Level 10

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)

 

 

 

 

 

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
Level: Powered On

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
RezaDorrani
Level 10

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-

 

RezaDorrani
Level 10

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
Level: Powered On

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

RezaDorrani
Level 10

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
Level: Powered On

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?

RezaDorrani
Level 10

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)

 

 

 

 

 

hraz
Level: Powered On

Re: Filter numbers

Got it. Thanks! I will try it out!

hraz
Level: Powered On

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

abm
Level 10

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

hraz
Level: Powered On

Re: Filter numbers

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

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 232 members 4,140 guests
Please welcome our newest community members: