web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Frustrated adding inte...
Power Automate
Answered

Frustrated adding integer variables

(0) ShareShare
ReportReport
Posted on by 91

I can't believe this is so hard.

 

I want to total a number of income sources based on a Microsoft Form submission. I tried first creating a JSON object with all the variables in it. Couldn't get them to add. After spending half a day on it I started working on a longer method.

 

Initialize intSalary as integer

Initialize intIA as integer

Initialize intPension... as integer etc.

 

I then tried to compose add(variables('intSalary'),add(variables('intIA'),variables('intPension'))) and that fails.

 

I then tried Set Variable for intSalary, using int(item()?['intSalary']) so I can see if setting them is needed. (It shouldn't be, because I've set the values upon declaration).

 

From the hints I've seen in the errors the initial problem is that the submitted form fields are being seen as strings, even though they are integers. As such, when I try to declare the variable using that value it fails because it expects an integer and not a string. I tried to figure out how to convert it to an integer - using the method above that I used when describing Set Variable.

 

Categories:
I have the same question (0)
  • Verified answer
    wskinnermctc Profile Picture
    6,519 Moderator on at

    Use the int() expression. This will convert the string to an integer.

     

    I just had this complaint the other day about MS Forms having number restricted answers but they do not pass as a number, they pass as a string.

     

    If your number does not have any decimal places you can use the int() expression.

    If your number will have decimals you need to use the float() expression.

     

    String Number With Decimal ExampleString Number With Decimal ExampleString Number With Decimal Results - Integer ErrorString Number With Decimal Results - Integer Error

     

     

    I made an example showing what happens if the number has decimals and you use the int() expression. It will error. 

     

    Let me know if this works for you,

     

  • clicker666 Profile Picture
    91 on at

    That worked. Its the end of day here. I'll try the add tomorrow.

     

     

  • wskinnermctc Profile Picture
    6,519 Moderator on at

    Can you show and tell me more about the questions you are asking in your MS Form? 

    Are the responses to the form Text fields or choices? Are they number restricted?

     

    Are you asking to total the amount of income like Salary + Retirement added together 100,000+50,000 = 150,000?

     

    Or are you asking how many types of income? Like Salary + Retirement = 2

     

     

  • clicker666 Profile Picture
    91 on at

    They are number restricted text fields. I'm asking for the amounts as in your first example.

     

    I'm going to try the mass declaration of variables in JSON again now that I think I have a better understanding of what was happening. I'll update once I have a chance to do some work on this.

  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @clicker666 

     

    The expression you provided looks good to me.

     

    add(variables('intSalary'),add(variables('intIA'),variables('intPension')))

     

    Make sure there are no blank values? Are these values optional or mandatory in Forms?

     

    If its blank then add an IF condition to check whether its blank or not. For blank set the value default as zero.

     

    Thanks

     

     

  • clicker666 Profile Picture
    91 on at

    OK. So I managed to get all the values pulled from the form into an object, declaring all my variables. Much cleaner!

     

    fininputs.png

     

    I'm a little confused on how to get the float implemented here though. Not sure of the syntax or if this is even the right way.... or should I use Set Variable instead?

     

    floaty.png

     

    If I can figure out how to populate those variables I should be good to go on the math. 

  • Verified answer
    abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @clicker666 

     

    Try the below. You need to leave it blank and use is not equal to under the condition.

     

    image.png

  • clicker666 Profile Picture
    91 on at

    Of course lol. I was thinking in code, thought I had to put it in JSON. I've been using Condition all throughout haha.

  • clicker666 Profile Picture
    91 on at

    Well, that didn't work.

     

    So, I've declared all my variables in JSON. I then try to use the compose function as shown in the pics earlier in the thread to convert the string to float, and get the error below.

     

    Screenshot 2023-07-24 103015.png

     

    I didn't see a val function, so it's starting to look like (unless you have some insight on the issue above) I will have to do this the tedious way:

     

    Initialize two variables, one string and one float.

    Set the string variable based on the form input.

    Run a condition to determine if the string variable is empty.

    Set the float variable if the string is not empty, set the float variable to 0 if empty.

    Repeat for each and every string variable. 🤔

  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @clicker666 

     

    Did you declared your variable outside the loop or inside?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard