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

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
Super User
Super User

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

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
Super User
Super User

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

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
Super User

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

HI @Armyfrog 

 

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

 

Highlighted
Armyfrog
Level: Powered On

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

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!
Super User
Super User

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

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

Super User
Super User

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

Hi @Armyfrog 

 

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

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 Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (3,616)