cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Resident Rockstar
Resident Rockstar

How to detect if a character is an integer, or not.

I need to check if the first character of a string is a number.  Is there an easy way to do this?  I need to do this in an expression.  Some languages have IfError() to trap an error, or some other way?

 

This is what would work for me (if the error statement was available)

 

 

if(IfError(int(substring(item()?['ProductID'],0,1)),0,1)

 

 

 

What I do NOT want to do (but would work):

 

 

if(equals(substring(item()?['ProductID'],0,1),'0'),1, 
   if(equals(substring(item()?['ProductID'],0,1),'1'),1,
      if(equals(substring(item()?['ProductID'],0,1),'2'),1,
         if(equals(substring(item()?['ProductID'],0,1),'3'),1,    
            if(equals(substring(item()?['ProductID'],0,1),'4'),1, 
               if(equals(substring(item()?['ProductID'],0,1),'5'),1, 
                  if(equals(substring(item()?['ProductID'],0,1),'6'),1, 
                     if(equals(substring(item()?['ProductID'],0,1),'7'),1,    
                        if(equals(substring(item()?['ProductID'],0,1),'8'),1,
                           if(equals(substring(item()?['ProductID'],0,1),'9'),1,
   0))))))))))

 

 

 

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

I gave up on this.  Ended up changing the View in SQL.  It has proper command statements for such things.

CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'Kel%') THEN 2 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'RMA%') THEN 3 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'DC%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'NW%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'BT%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'DC%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'HF%') THEN 5 ELSE 
CASE WHEN (ISNUMERIC(SUBSTRING(dbo.OrderDetail.ProductID, 1, 6)) = 1) THEN 4 ELSE 
CASE WHEN (ISNUMERIC(LEFT(dbo.OrderDetail.ProductID, 1)) = 1 AND SUBSTRING(dbo.OrderDetail.ProductID, 2, 1) = '-') THEN 5 ELSE 
CASE WHEN (LEFT(dbo.OrderDetail.ProductID, 1) = 'K' AND ISNUMERIC(SUBSTRING(dbo.OrderDetail.ProductID, 2, 4)) = 1) 
THEN 4 ELSE 1 END END END END END END END END END END AS OrderType

 

View solution in original post

3 REPLIES 3
Dual Super User III
Dual Super User III

@martinav 

Mmmm... to trap errors in power automate you need to implement a try-catch action blocks based approach.

https://poszytek.eu/en/microsoft-en/office-365-en/powerautomate-en/try-catch-pattern-in-microsoft-fl...

 

I don't believe it is possible to implement it by means of a pure expression based approach, but if someone else has managed to do that, more than happy to learn one more thing

 

Now, just guessing if a lexicographical order based expression I.e. the first character is greater or equal to character '0' and less or equal to character '9' is could help you to achieve your requirements

 

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Yea, the action block method is great, but will not work in this case, because this statement is with a Select action.  I was going to be happy with the nested if(), which worked great for one condition.  However, now I have the need to detect if the first SIX characters of a string constitute a number.  That will break the lexicographical order idea.  Which was a good one, btw.  But things have become more complex.  

 

What I am actually doing, is moving this condition statement to create another data column in a Flow Select action.   This is the statement in powerapps:

 

 

If(StartsWith(OrderNumOB,"Kel"),2,
              StartsWith(OrderNumOB,"RMA"),3,
              StartsWith(ProductID,"HF"),5,
              StartsWith(ProductID,"DC"),5,
              StartsWith(ProductID,"NW"),5,
              IsMatch(ProductID,Match.Digit) And Mid(ProductID,2,1)="-",5,
              StartsWith(ProductID,"BT"),5,
              StartsWith(ProductID,"K") And IsNumeric(Mid(ProductID,2,1)),4,
              IsMatch(ProductID, Match.Digit & Match.Digit & Match.Digit & Match.Digit & Match.Digit & Match.Digit),4,1)

 

This is what I have so far  in an expression.  This works perfectly at this point.  However, I need to add the last two lines from above, into the expression.

 

if(startsWith(item()?['OrderNumOB'],'Kel'),2,
  if(startsWith(item()?['OrderNumOB'],'RMA'),3,
    if(startsWith(item()?['ProductID'],'HF'),5,
      if(startsWith(item()?['ProductID'],'DC'),5,
        if(startsWith(item()?['ProductID'],'NW'),5,
           if(startsWith(item()?['ProductID'],'BT'),5,
   if(and(
      equals(
         if(equals(substring(item()?['ProductID'],0,1),'0'),1, 
         if(equals(substring(item()?['ProductID'],0,1),'1'),1,
         if(equals(substring(item()?['ProductID'],0,1),'2'),1,
         if(equals(substring(item()?['ProductID'],0,1),'3'),1,    
         if(equals(substring(item()?['ProductID'],0,1),'4'),1, 
         if(equals(substring(item()?['ProductID'],0,1),'5'),1, 
         if(equals(substring(item()?['ProductID'],0,1),'6'),1, 
         if(equals(substring(item()?['ProductID'],0,1),'7'),1,    
         if(equals(substring(item()?['ProductID'],0,1),'8'),1,
         if(equals(substring(item()?['ProductID'],0,1),'9'),1,
         0)))))))))),
      1),
      equals(substring(item()?['ProductID'],1,1),'-')),5,
 
0))))))

 

I gave up on this.  Ended up changing the View in SQL.  It has proper command statements for such things.

CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'Kel%') THEN 2 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'RMA%') THEN 3 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'DC%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'NW%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'BT%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'DC%') THEN 5 ELSE 
CASE WHEN (dbo.OrderDetail.OrderNumber LIKE 'HF%') THEN 5 ELSE 
CASE WHEN (ISNUMERIC(SUBSTRING(dbo.OrderDetail.ProductID, 1, 6)) = 1) THEN 4 ELSE 
CASE WHEN (ISNUMERIC(LEFT(dbo.OrderDetail.ProductID, 1)) = 1 AND SUBSTRING(dbo.OrderDetail.ProductID, 2, 1) = '-') THEN 5 ELSE 
CASE WHEN (LEFT(dbo.OrderDetail.ProductID, 1) = 'K' AND ISNUMERIC(SUBSTRING(dbo.OrderDetail.ProductID, 2, 4)) = 1) 
THEN 4 ELSE 1 END END END END END END END END END END AS OrderType

 

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Top Kudoed Authors
Users online (8,007)