cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Sharepoint column formatted as number with 0 decimals being brought into switch comparison as a float?

I am trying to setup a switch statement to compare category numbers 1-15 to send out seperate e-mails depending on category # listed on the sharepoint list, but for some reason I keep getting the error that switch only accepts int/str and the value presented is a float.

 

 

Anyone know how i can get around this?

1 ACCEPTED SOLUTION

Accepted Solutions
Resident Rockstar
Resident Rockstar

You can use expression to convert. It is a nested expression, the first one converts to a string, the second converts string to a int, if you are just using it in the switch and doesnt matter if its a number just string string(insertvalue)

 

int(string(insertvaluehere))

View solution in original post

5 REPLIES 5
Resident Rockstar
Resident Rockstar

You can use expression to convert. It is a nested expression, the first one converts to a string, the second converts string to a int, if you are just using it in the switch and doesnt matter if its a number just string string(insertvalue)

 

int(string(insertvaluehere))

View solution in original post

Super User II
Super User II

HI @Anonymous 

 

Indeed that's quite annoying, but it's the behavior when fetching the number. 

 

I replicated your issue. It's this what you're getting correct?

small-Screenshot 2019-12-05 at 11.00.12.png

 

There's no way in Power Automation to convert from float to int, so we have to work our way around the issue. And believe me, this is a big workaround, but it works.

 

To solve this add a compose step before and do the following:

 

 

int(split(string(body('Get_item')?['increment']),'.')[0])

 

 

In my case, the column in SharePoint is called increment, but please replace it with the name of your column. The same for the action name ('Get_item'). 

 

I know, right? Crazy. Let's break this down into steps:

  1. First, you get the item from SharePoint. In my case is the body('Get_item')?['increment'] that is a float
  2. Then convert it to a string. This is represented in the string(body('Get_item')?['increment']) part of the formula.
  3. Then split it using the ".". With this, you'll get the number part, and, since you're configuring in SharePoint that it has zero decimal points, the value will always be zero, so we can ignore it. We get this by doing the string(body('Get_item')?['increment']
  4. Then we need to fetch the numeric part. That's where the [0] comes into play since we're getting an array from the split. 
  5. Finally we use the int to convert the string back to the int.

 

You'll get something like this.

small-Screenshot_2019-12-05_at_11_11_16.jpg

 

The run is now successful:

small-Screenshot_2019-12-05_at_11_14_53.jpg

 

Does all of this make sense to you. If not please let me know and I'll explain further.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

 

Anonymous
Not applicable

That is exactly the error I’m receiving. I will try your solution as soon as I get back to my computer. I’ve rebuilt this flow more times than I care to admit at this point, but hey that’s the fun part of learning I suppose!

no need for extra steps you can just include the expression in the switch 🙂

Hi @Anonymous 

 

I fully understand :). This was something that happened to me in the past and drove me crazy in the past.

 

You can also like @Gristy mentioned, and put all in the switch. This is a question of preference. I like to have individual steps so that I can debug stuff while it's running, but both of them work. Thanks @Gristy for the suggestion.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

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
Users online (4,558)